From b0a421e8c1edf21466756f1354a481273c2cb362 Mon Sep 17 00:00:00 2001 From: Jason Merrill <jason@redhat.com> Date: Mon, 7 Jun 2010 16:43:01 -0400 Subject: [PATCH] re PR c++/44401 (Doesn't correctly hide injected class name) PR c++/44401 * parser.c (cp_parser_lookup_name): Fix naming the constructor. From-SVN: r160399 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/parser.c | 24 +++++++++++++----------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/tc1/dr147.C | 10 ++++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 322023008968..5f74ab9ce32b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2010-06-07 Jason Merrill <jason@redhat.com> + PR c++/44401 + * parser.c (cp_parser_lookup_name): Fix naming the constructor. + * cp-tree.h (COMPLETE_OR_OPEN_TYPE_P): New macro. * init.c (build_offset_ref): Use it. * pt.c (maybe_process_partial_specialization): Use it. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index eb347e24bae7..92f778619eb1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18365,6 +18365,14 @@ cp_parser_lookup_name (cp_parser *parser, tree name, if (dependent_p) pushed_scope = push_scope (parser->scope); + /* If the PARSER->SCOPE is a template specialization, it + may be instantiated during name lookup. In that case, + errors may be issued. Even if we rollback the current + tentative parse, those errors are valid. */ + decl = lookup_qualified_name (parser->scope, name, + tag_type != none_type, + /*complain=*/true); + /* 3.4.3.1: In a lookup in which the constructor is an acceptable lookup result and the nested-name-specifier nominates a class C: * if the name specified after the nested-name-specifier, when @@ -18380,17 +18388,11 @@ cp_parser_lookup_name (cp_parser *parser, tree name, shall be used only in the declarator-id of a declaration that names a constructor or in a using-declaration. */ if (tag_type == none_type - && CLASS_TYPE_P (parser->scope) - && constructor_name_p (name, parser->scope)) - name = ctor_identifier; - - /* If the PARSER->SCOPE is a template specialization, it - may be instantiated during name lookup. In that case, - errors may be issued. Even if we rollback the current - tentative parse, those errors are valid. */ - decl = lookup_qualified_name (parser->scope, name, - tag_type != none_type, - /*complain=*/true); + && DECL_SELF_REFERENCE_P (decl) + && same_type_p (DECL_CONTEXT (decl), parser->scope)) + decl = lookup_qualified_name (parser->scope, ctor_identifier, + tag_type != none_type, + /*complain=*/true); /* If we have a single function from a using decl, pull it out. */ if (TREE_CODE (decl) == OVERLOAD diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fd6994a3c36e..50afa0dd51de 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-06-07 Jason Merrill <jason@redhat.com> + + PR c++/44401 + * g++.dg/tc1/dr147.C: Test case of member with same name as class. + 2010-06-07 Jakub Jelinek <jakub@redhat.com> PR c++/44444 diff --git a/gcc/testsuite/g++.dg/tc1/dr147.C b/gcc/testsuite/g++.dg/tc1/dr147.C index a29986b55598..6799b7dccad0 100644 --- a/gcc/testsuite/g++.dg/tc1/dr147.C +++ b/gcc/testsuite/g++.dg/tc1/dr147.C @@ -54,3 +54,13 @@ struct D: C::C { D(): C::C() { } }; + +// And if lookup doesn't find the injected-class-name, we aren't naming the +// constructor (c++/44401). + +struct E +{ + int E; +}; + +int E::*p = &E::E; -- GitLab