c++: adjust the extra ; warning [PR113760]

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.
This commit is contained in:
Marek Polacek
2024-02-13 16:21:32 -05:00
parent ab71fd7ac7
commit 6fec511f2d
6 changed files with 24 additions and 5 deletions

View 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 ();

View File

@@ -0,0 +1,9 @@
// DR 1693, Superfluous semicolons in class definitions
// PR c++/113760
// { dg-do compile }
// { dg-options "" }
struct S {
int a;
;
};

View File

@@ -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 } }
};

View File

@@ -1,3 +1,4 @@
// { dg-do compile { target c++98_only } }
/* { dg-options "-fdiagnostics-show-caret -Wpedantic" } */
/* Struct with extra semicolon. */

View 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 } }
};

View 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
};