From: Jonathan Wakely Date: Wed, 17 Jun 2020 19:26:13 +0000 (+0100) Subject: c++: Fix bogus "does not declare anything" warning (PR 66159) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d392babbeb6cb531ab8b1ec68fde9ffd36373a6e;p=gcc.git c++: Fix bogus "does not declare anything" warning (PR 66159) G++ gives a bogus warning for 'struct A; using B = struct ::A;' complaining that the elaborated-type-specifier doesn't declare anything. That's true, but it's not trying to declare struct ::A, just refer to it unambiguously. Do not emit the warning unless we're actually parsing a declaration. gcc/cp/ChangeLog: PR c++/66159 * parser.c (cp_parser_elaborated_type_specifier): Do not warn unless in a declaration. gcc/testsuite/ChangeLog: PR c++/66159 * g++.dg/warn/forward-inner.C: Check alias-declaration using elaborated-type-specifier. --- diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 69839baa712..815582c825e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18953,7 +18953,8 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, here. */ if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON) - && !is_friend && !processing_explicit_instantiation) + && !is_friend && is_declaration + && !processing_explicit_instantiation) warning (0, "declaration %qD does not declare anything", decl); type = TREE_TYPE (decl); diff --git a/gcc/testsuite/g++.dg/warn/forward-inner.C b/gcc/testsuite/g++.dg/warn/forward-inner.C index 5336d4ed946..d7b93f8ad08 100644 --- a/gcc/testsuite/g++.dg/warn/forward-inner.C +++ b/gcc/testsuite/g++.dg/warn/forward-inner.C @@ -70,7 +70,7 @@ template class TC6::TC7; // Valid explicit instantiation, no warning // Verify that friend declarations, also easy to confuse with forward -// declrations, are similarly not warned about. +// declarations, are similarly not warned about. class C8 { public: class C9 { }; @@ -79,3 +79,10 @@ class C10 { public: friend class C8::C9; // Valid friend declaration, no warning }; + +#if __cplusplus >= 201103L +// Verify that alias-declarations using an elaborated-type-specifier and +// nested-name-specifier are not warned about (PR c++/66159). +struct C11; +using A1 = struct ::C11; // Valid alias-decl, no warning +#endif