diff mbox series

c++: Allow empty-declaration in C++11 and later (PR 96068)

Message ID 20200706150150.GA682509@redhat.com
State New
Headers show
Series c++: Allow empty-declaration in C++11 and later (PR 96068) | expand

Commit Message

Jonathan Wakely July 6, 2020, 3:01 p.m. UTC
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.


Tested x86_64-linux, OK for trunk?
commit 0070906d6384341d356e7c925f99e978e748136a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jul 6 15:58:33 2020 +0100

    c++: Allow empty-declaration in C++11 and later (PR 96068)
    
    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.

Comments

Nathan Sidwell July 6, 2020, 3:11 p.m. UTC | #1
On 7/6/20 11:01 AM, Jonathan Wakely wrote:
> 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.
> 
> 
> Tested x86_64-linux, OK for trunk?

ok thanks.
diff mbox series

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 815582c825e..6e7637c6016 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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.  */
diff --git a/gcc/testsuite/g++.old-deja/g++.bugs/900404_04.C b/gcc/testsuite/g++.old-deja/g++.bugs/900404_04.C
index 04ff6690549..86117939637 100644
--- a/gcc/testsuite/g++.old-deja/g++.bugs/900404_04.C
+++ b/gcc/testsuite/g++.old-deja/g++.bugs/900404_04.C
@@ -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; }
diff --git a/gcc/testsuite/g++.old-deja/g++.law/missed-error2.C b/gcc/testsuite/g++.old-deja/g++.law/missed-error2.C
index ee69e1156cc..eaf8c01b679 100644
--- a/gcc/testsuite/g++.old-deja/g++.law/missed-error2.C
+++ b/gcc/testsuite/g++.old-deja/g++.law/missed-error2.C
@@ -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 "" } .*