Hi, On 27/05/2016 16:56, Jason Merrill wrote:
Let's go with the second patch.
Good. Then I'm going to commit the below after an additional round of testing with an updated tree.
Thanks! Paolo. ///////////////////////
/cp 2016-05-27 Paolo Carlini <paolo.carl...@oracle.com> PR c++/60385 * name-lookup.c (push_namespace): Return bool, false when pushdecl fails. * name-lookup.h (push_namespace): Adjust declaration. * parser.c (cp_parser_namespace_definition): Check push_namespace return value. /testsuite 2016-05-27 Paolo Carlini <paolo.carl...@oracle.com> PR c++/60385 * g++.dg/parse/namespace13.C: New.
Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 236830) +++ cp/name-lookup.c (working copy) @@ -3701,9 +3701,10 @@ handle_namespace_attrs (tree ns, tree attributes) } /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we - select a name that is unique to this compilation unit. */ + select a name that is unique to this compilation unit. Returns FALSE if + pushdecl fails, TRUE otherwise. */ -void +bool push_namespace (tree name) { tree d = NULL_TREE; @@ -3777,7 +3778,11 @@ push_namespace (tree name) TREE_PUBLIC (d) = 0; else TREE_PUBLIC (d) = 1; - pushdecl (d); + if (pushdecl (d) == error_mark_node) + { + timevar_cond_stop (TV_NAME_LOOKUP, subtime); + return false; + } if (anon) { /* Clear DECL_NAME for the benefit of debugging back ends. */ @@ -3795,6 +3800,7 @@ push_namespace (tree name) current_namespace = d; timevar_cond_stop (TV_NAME_LOOKUP, subtime); + return true; } /* Pop from the scope of the current namespace. */ Index: cp/name-lookup.h =================================================================== --- cp/name-lookup.h (revision 236830) +++ cp/name-lookup.h (working copy) @@ -312,7 +312,7 @@ extern tree push_inner_scope (tree); extern void pop_inner_scope (tree, tree); extern void push_binding_level (cp_binding_level *); -extern void push_namespace (tree); +extern bool push_namespace (tree); extern void pop_namespace (void); extern void push_nested_namespace (tree); extern void pop_nested_namespace (tree); Index: cp/parser.c =================================================================== --- cp/parser.c (revision 236830) +++ cp/parser.c (working copy) @@ -17549,7 +17549,7 @@ cp_parser_namespace_definition (cp_parser* parser) } /* Start the namespace. */ - push_namespace (identifier); + bool ok = push_namespace (identifier); /* Parse any nested namespace definition. */ if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)) @@ -17582,7 +17582,7 @@ cp_parser_namespace_definition (cp_parser* parser) /* "inline namespace" is equivalent to a stub namespace definition followed by a strong using directive. */ - if (is_inline) + if (is_inline && ok) { tree name_space = current_namespace; /* Set up namespace association. */ @@ -17610,7 +17610,8 @@ cp_parser_namespace_definition (cp_parser* parser) pop_namespace (); /* Finish the namespace. */ - pop_namespace (); + if (ok) + pop_namespace (); /* Look for the final `}'. */ cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); } Index: testsuite/g++.dg/parse/namespace13.C =================================================================== --- testsuite/g++.dg/parse/namespace13.C (revision 0) +++ testsuite/g++.dg/parse/namespace13.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/60385 + +float foo4(); // { dg-message "previous declaration" } + +namespace foo4 // { dg-error "redeclared" } +{ + struct bar6 + { + friend wchar_t bar1(); + }; +}