c++: Allow empty-declaration in C++11 and later (PR 96068)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 6 Jul 2020 14:58:33 +0000 (15:58 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 6 Jul 2020 16:12:23 +0000 (17:12 +0100)
Since C++11 a semim-colon on its own at namespace scope is not invalid,
so do not give a pedantic diagnostic about it.

gcc/cp/ChangeLog:

PR c++/96068
* parser.c (cp_parser_toplevel_declaration): Only do pedwarn for
empty-declaration in C++98.

gcc/testsuite/ChangeLog:

* g++.old-deja/g++.bugs/900404_04.C: Add c++98_only selector to
dg-error for extra ';'.
* g++.old-deja/g++.law/missed-error2.C: Likewise.

gcc/cp/parser.c
gcc/testsuite/g++.old-deja/g++.bugs/900404_04.C
gcc/testsuite/g++.old-deja/g++.law/missed-error2.C

index 815582c..6e7637c 100644 (file)
@@ -13502,10 +13502,11 @@ cp_parser_toplevel_declaration (cp_parser* parser)
     cp_parser_pragma (parser, pragma_external, NULL);
   else if (token->type == CPP_SEMICOLON)
     {
-      /* A declaration consisting of a single semicolon is
-        invalid.  Allow it unless we're being pedantic.  */
       cp_lexer_consume_token (parser->lexer);
-      pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
+      /* A declaration consisting of a single semicolon is invalid
+       * before C++11.  Allow it unless we're being pedantic.  */
+      if (cxx_dialect < cxx11)
+       pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
     }
   else
     /* Parse the declaration itself.  */
index 04ff669..8611793 100644 (file)
@@ -7,12 +7,14 @@
 // elaborated-type-specifier with class key, or an enum-specifier. The
 // declaration below contains neither.
 
-// g++ fails to flag errors for such usage.
+// Since C++11 this is allowed as an empty-declaration.
+
+// g++ fails to flag errors for such usage in C++98.
 
 // keywords: semicolon, vacuous, file scope, declaration
 
 int i;
 
-;                      // { dg-error "extra ';'" } 
+;                      // { dg-error "extra ';'" "" { target c++98_only } 0 
 
 int main () { return 0; }
index ee69e11..eaf8c01 100644 (file)
@@ -15,9 +15,9 @@
 #endif
 
 inline int max(int a, int b) {return a > b ? a : b;}; // { dg-message "note" } 
- // { dg-error "extra ';'" "extra ;" { target *-*-* } .-1 }
+ // { dg-error "extra ';'" "extra ;" { target c++98_only } .-1 }
 inline double max(double a, double b) {return a > b ? a : b;}; // { dg-message "note" } candidate
- // { dg-error "extra ';'" "extra ;" { target *-*-* } .-1 }
+ // { dg-error "extra ';'" "extra ;" { target c++98_only } .-1 }
 
 int main() {
    static void foo(int i, int j, double x, double y) ;// { dg-error "" } .*