This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/38278


The code that checks to see if we're dealing with a constructor declarator causes us to call cp_parser_class_name in a speculative context, so we got an error if we use a name that was previously declared as a parenthesized declarator. This patch moves the call to maybe_note_name_used_in_class until after we decide that this is really a class name, which is still wrong, but is masked by the pre-existing bug which I've just filed as 38313. When we fix that bug this will need to be dealt with again (and the testcase for 38313 will trip this issue as well).

Tested x86_64-pc-linux-gnu, applied to trunk.

2008-11-28  Jason Merrill  <jason@redhat.com>

	PR c++/38278
	* parser.c (cp_parser_class_name): Only call 
	maybe_note_name_used_in_class if we actually found a class name.
	* g++.dg/lookup/name-clash8.C: New test.

Index: cp/parser.c
===================================================================
*** cp/parser.c	(revision 142211)
--- cp/parser.c	(working copy)
*************** cp_parser_class_name (cp_parser *parser,
*** 14686,14691 ****
--- 14686,14692 ----
    tree scope;
    bool typename_p;
    cp_token *token;
+   tree identifier = NULL_TREE;
  
    /* All class-names start with an identifier.  */
    token = cp_lexer_peek_token (parser->lexer);
*************** cp_parser_class_name (cp_parser *parser,
*** 14711,14717 ****
        && !cp_parser_nth_token_starts_template_argument_list_p (parser, 2))
      {
        cp_token *identifier_token;
-       tree identifier;
        bool ambiguous_p;
  
        /* Look for the identifier.  */
--- 14712,14717 ----
*************** cp_parser_class_name (cp_parser *parser,
*** 14767,14775 ****
  		}
  	      return error_mark_node;
  	    }
- 	  else if (decl != error_mark_node
- 		   && !parser->scope)
- 	    maybe_note_name_used_in_class (identifier, decl);
  	}
      }
    else
--- 14767,14772 ----
*************** cp_parser_class_name (cp_parser *parser,
*** 14819,14824 ****
--- 14816,14823 ----
  
    if (decl == error_mark_node)
      cp_parser_error (parser, "expected class-name");
+   else if (identifier && !parser->scope)
+     maybe_note_name_used_in_class (identifier, decl);
  
    return decl;
  }
Index: testsuite/g++.dg/lookup/name-clash8.C
===================================================================
*** testsuite/g++.dg/lookup/name-clash8.C	(revision 0)
--- testsuite/g++.dg/lookup/name-clash8.C	(revision 0)
***************
*** 0 ****
--- 1,8 ----
+ // PR c++/38278
+ 
+ struct foo { };
+ void bar();
+ 
+ struct baz {
+   static foo (bar)();
+ };

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]