aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-07-06 15:58:33 +0100
committerJonathan Wakely <jwakely@redhat.com>2020-07-06 17:12:23 +0100
commit92414bb6b077642eefc24080637b6bc766499391 (patch)
tree668571cf17cbe28922e9198f4441e5d69566ade1
parentdccbf1e2a6e544f71b4a5795f0c79015db019fc3 (diff)
downloadgcc-92414bb6b077642eefc24080637b6bc766499391.zip
gcc-92414bb6b077642eefc24080637b6bc766499391.tar.gz
gcc-92414bb6b077642eefc24080637b6bc766499391.tar.bz2
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.
-rw-r--r--gcc/cp/parser.c7
-rw-r--r--gcc/testsuite/g++.old-deja/g++.bugs/900404_04.C6
-rw-r--r--gcc/testsuite/g++.old-deja/g++.law/missed-error2.C4
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 "" } .*