]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: adjust the extra ; warning [PR113760]
authorMarek Polacek <polacek@redhat.com>
Tue, 13 Feb 2024 21:21:32 +0000 (16:21 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 13 Feb 2024 22:41:21 +0000 (17:41 -0500)
A minimal fix to quash an extra ; warning.  I have a more complete
patch for GCC 15.

DR 1693
PR c++/113760

gcc/cp/ChangeLog:

* parser.cc (cp_parser_member_declaration): Only pedwarn about an extra
semicolon in C++98.

gcc/testsuite/ChangeLog:

* g++.dg/semicolon-fixits.C: Run in C++98 only.
* g++.dg/warn/pedantic2.C: Adjust dg-warning.
* g++.old-deja/g++.jason/parse11.C: Adjust dg-error.
* g++.dg/DRs/dr1693-1.C: New test.
* g++.dg/DRs/dr1693-2.C: New test.

gcc/cp/parser.cc
gcc/testsuite/g++.dg/DRs/dr1693-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/DRs/dr1693-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/semicolon-fixits.C
gcc/testsuite/g++.dg/warn/pedantic2.C
gcc/testsuite/g++.old-deja/g++.jason/parse11.C

index 68ab74d70b9c761600077befe0fec209e39990c1..9d0914435fb119a5a38df7ce9c70eefde749c1e1 100644 (file)
@@ -27999,7 +27999,7 @@ cp_parser_member_declaration (cp_parser* parser)
       if (!decl_specifiers.any_specifiers_p)
        {
          cp_token *token = cp_lexer_peek_token (parser->lexer);
-         if (!in_system_header_at (token->location))
+         if (cxx_dialect < cxx11 && !in_system_header_at (token->location))
            {
              gcc_rich_location richloc (token->location);
              richloc.add_fixit_remove ();
diff --git a/gcc/testsuite/g++.dg/DRs/dr1693-1.C b/gcc/testsuite/g++.dg/DRs/dr1693-1.C
new file mode 100644 (file)
index 0000000..ed27026
--- /dev/null
@@ -0,0 +1,9 @@
+// DR 1693, Superfluous semicolons in class definitions
+// PR c++/113760
+// { dg-do compile }
+// { dg-options "" }
+
+struct S {
+  int a;
+  ;
+};
diff --git a/gcc/testsuite/g++.dg/DRs/dr1693-2.C b/gcc/testsuite/g++.dg/DRs/dr1693-2.C
new file mode 100644 (file)
index 0000000..c52259d
--- /dev/null
@@ -0,0 +1,9 @@
+// DR 1693, Superfluous semicolons in class definitions
+// PR c++/113760
+// { dg-do compile }
+// { dg-options "-pedantic-errors" }
+
+struct S {
+  int a;
+  ;        // { dg-error "extra" "" { target c++98_only } }
+};
index a9cc783b1725ae34a02ebe06cdcc62f7741986bb..198e306c950d627b67b0e5aae25c4fe9b6e3c017 100644 (file)
@@ -1,3 +1,4 @@
+// { dg-do compile { target c++98_only } }
 /* { dg-options "-fdiagnostics-show-caret -Wpedantic" } */
 
 /* Struct with extra semicolon.  */
index 6c834162c1b63598098978495b78b0625f937272..37d77daaef3f89d43cb766145fc61a127d82cf4e 100644 (file)
@@ -5,6 +5,6 @@ class foo
   foo() {};
   void bar() {};
 
-  foo(int) {};;  // { dg-warning "extra" }
-  void bar(int) {};;  // { dg-warning "extra" }
+  foo(int) {};;  // { dg-warning "extra" "" { target c++98_only } }
+  void bar(int) {};;  // { dg-warning "extra" "" { target c++98_only } }
 };
index 40864c108ba02bbff79f611c8fc60facd6af7124..157a9c46287df8dbbb1aad40df1e2035a53e7ba0 100644 (file)
@@ -3,7 +3,7 @@
 
 class aClass 
 { 
-  ; // { dg-error "" } missing declaration
+  ; // { dg-error "" "" { target c++98_only } } missing declaration
 private: 
-  ; // { dg-error "" } missing declaration
+  ; // { dg-error "" "" { target c++98_only } } missing declaration
 };