From 92414bb6b077642eefc24080637b6bc766499391 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 6 Jul 2020 15:58:33 +0100 Subject: [PATCH] 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. --- gcc/cp/parser.c | 7 ++++--- gcc/testsuite/g++.old-deja/g++.bugs/900404_04.C | 6 ++++-- gcc/testsuite/g++.old-deja/g++.law/missed-error2.C | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 815582c..6e7637c 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 04ff669..8611793 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 ee69e11..eaf8c01 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 "" } .* -- 2.7.4