From patchwork Wed Apr 27 05:15:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/42687 (arg-dependent lookup regression) Date: Tue, 26 Apr 2011 19:15:10 -0000 From: Jason Merrill X-Patchwork-Id: 92982 Message-Id: <4DB7A65E.5000706@redhat.com> To: gcc-patches List When we fixed using explicit scope to suppress virtual calling, it broke using parentheses to suppress argument-dependent lookup. Fixed thus. Tested x86_64-pc-linux-gnu, applied to trunk, 4.4, 4.5 and 4.6. commit 2bc3ed125eab1075ea18c7c80e5ab908130861fd Author: Jason Merrill Date: Tue Apr 26 21:39:34 2011 -0400 PR c++/42687 * parser.c (cp_parser_primary_expression): Set *idk to CP_ID_KIND_NONE for a parenthesized identifier. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 6da285e..68ce052 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3437,6 +3437,12 @@ cp_parser_primary_expression (cp_parser *parser, `&A::B' might be a pointer-to-member, but `&(A::B)' is not. */ finish_parenthesized_expr (expr); + /* DR 705: Wrapping an unqualified name in parentheses + suppresses arg-dependent lookup. We want to pass back + CP_ID_KIND_QUALIFIED for suppressing vtable lookup + (c++/37862), but none of the others. */ + if (*idk != CP_ID_KIND_QUALIFIED) + *idk = CP_ID_KIND_NONE; } /* The `>' token might be the end of a template-id or template-parameter-list now. */ diff --git a/gcc/testsuite/g++.dg/lookup/koenig13.C b/gcc/testsuite/g++.dg/lookup/koenig13.C new file mode 100644 index 0000000..625a181 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig13.C @@ -0,0 +1,16 @@ +// PR c++/42687 +// DR 705 + +namespace N +{ + struct S { }; + void f(const S &) { } +} + +void f(const N::S &) { } + +int main() +{ + N::S v; + (f)(v); // no ambiguity: ADL is prevented with (), only ::f is considered +}