aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-06-21 20:26:54 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-06-21 20:26:54 +0000
commit4789c23be4e240285c12aecba22fdc6dfd100d11 (patch)
tree05b16bc28c81ce939db4fa93e08fff1a02cb1c55
parent9b15893c31a9fd926459123037c09b0ac64a5bd3 (diff)
downloadgcc-4789c23be4e240285c12aecba22fdc6dfd100d11.zip
gcc-4789c23be4e240285c12aecba22fdc6dfd100d11.tar.gz
gcc-4789c23be4e240285c12aecba22fdc6dfd100d11.tar.bz2
PR c++/64235 - missing syntax error with invalid alignas.
* parser.c (cp_parser_std_attribute_spec): Commit to tentative parse if there's a missing close paren. * g++.dg/parse/alignas1.C: New test. From-SVN: r272570
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/parser.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/parse/alignas1.C10
4 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0afd0e6..bc4fda7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2019-06-21 Marek Polacek <polacek@redhat.com>
+ PR c++/64235 - missing syntax error with invalid alignas.
+ * parser.c (cp_parser_std_attribute_spec): Commit to tentative parse
+ if there's a missing close paren.
+
PR c++/90490 - fix decltype issues in noexcept-specifier.
* except.c (build_noexcept_spec): Call
instantiate_non_dependent_expr_sfinae before
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 561d0e2..5cbc455 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26371,6 +26371,12 @@ cp_parser_std_attribute_spec (cp_parser *parser)
if (alignas_expr == error_mark_node)
return error_mark_node;
+ /* Missing ')' means the code cannot possibly be valid; go ahead
+ and commit to make sure we issue a hard error. */
+ if (cp_parser_uncommitted_to_tentative_parse_p (parser)
+ && cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
+ cp_parser_commit_to_tentative_parse (parser);
+
if (!parens.require_close (parser))
return error_mark_node;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 63bb7b9..44350ee 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-19 Marek Polacek <polacek@redhat.com>
+
+ PR c++/64235 - missing syntax error with invalid alignas.
+ * g++.dg/parse/alignas1.C: New test.
+
2019-06-21 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/67884
diff --git a/gcc/testsuite/g++.dg/parse/alignas1.C b/gcc/testsuite/g++.dg/parse/alignas1.C
new file mode 100644
index 0000000..8f36101
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/alignas1.C
@@ -0,0 +1,10 @@
+// PR c++/64235
+// { dg-do compile { target c++11 } }
+
+struct S {
+ double d;
+};
+
+struct alignas(sizeof(S) S1 { }; // { dg-error "expected '\\)' before 'S1'" }
+struct alignas(16 S2 { }; // { dg-error "expected '\\)' before 'S2'" }
+struct alignas(int S3 { }; // { dg-error "expected '\\)' before 'S3'" }