From: Paolo Carlini Date: Fri, 27 May 2016 19:19:23 +0000 (+0000) Subject: re PR c++/60385 (confused by earlier errors, bailing out) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8008c4d2bec3e5f54c149e08b62380f62641a965;p=gcc.git re PR c++/60385 (confused by earlier errors, bailing out) /cp 2016-05-27 Paolo Carlini 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 PR c++/60385 * g++.dg/parse/namespace13.C: New. From-SVN: r236835 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6c07df156bd..cdc2f5a46fd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2016-05-27 Paolo Carlini + + 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. + 2016-05-27 Ville Voutilainen PR c++/69855 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 568c75e80e4..11733700627 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -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. */ diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 2f8447a64c7..2cb129caad9 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -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); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 546aada5156..2a46d6fbde7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5ded2d41873..69206816dd7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-27 Paolo Carlini + + PR c++/60385 + * g++.dg/parse/namespace13.C: New. + 2016-05-26 Jeff Law * gcc.dg/tree-ssa/pr21417.c: Update expected output. diff --git a/gcc/testsuite/g++.dg/parse/namespace13.C b/gcc/testsuite/g++.dg/parse/namespace13.C new file mode 100644 index 00000000000..5a053846406 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/namespace13.C @@ -0,0 +1,11 @@ +// PR c++/60385 + +float foo4(); // { dg-message "previous declaration" } + +namespace foo4 // { dg-error "redeclared" } +{ + struct bar6 + { + friend wchar_t bar1(); + }; +}