aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2023-08-08 12:48:43 +1000
committerJason Merrill <jason@redhat.com>2023-08-08 16:03:25 -0400
commita90bd3ea6d1ba27b15476f0a768d7952c6723420 (patch)
tree2701dd6bf11608f0088a1d373b0cb9b9c88f774a
parente7cae4f873fe94c1af8401b8d0b53a192957215d (diff)
downloadgcc-a90bd3ea6d1ba27b15476f0a768d7952c6723420.zip
gcc-a90bd3ea6d1ba27b15476f0a768d7952c6723420.tar.gz
gcc-a90bd3ea6d1ba27b15476f0a768d7952c6723420.tar.bz2
c++: Report invalid id-expression in decltype [PR100482]
This patch ensures that any errors raised by finish_id_expression when parsing a decltype expression are properly reported, rather than potentially going ignored and causing invalid code to be accepted. We can also now remove the separate check for templates without args as this is also checked for in finish_id_expression. PR c++/100482 gcc/cp/ChangeLog: * parser.cc (cp_parser_decltype_expr): Report errors raised by finish_id_expression. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/decltype-100482.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
-rw-r--r--gcc/cp/parser.cc22
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/decltype-100482.C12
2 files changed, 23 insertions, 11 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index ba15a09..5b6d03e 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -16520,10 +16520,6 @@ cp_parser_decltype_expr (cp_parser *parser,
expr = cp_parser_lookup_name_simple (parser, expr,
id_expr_start_token->location);
- if (expr && TREE_CODE (expr) == TEMPLATE_DECL)
- /* A template without args is not a complete id-expression. */
- expr = error_mark_node;
-
if (expr
&& expr != error_mark_node
&& TREE_CODE (expr) != TYPE_DECL
@@ -16544,13 +16540,17 @@ cp_parser_decltype_expr (cp_parser *parser,
&error_msg,
id_expr_start_token->location));
- if (expr == error_mark_node)
- /* We found an id-expression, but it was something that we
- should not have found. This is an error, not something
- we can recover from, so note that we found an
- id-expression and we'll recover as gracefully as
- possible. */
- id_expression_or_member_access_p = true;
+ if (error_msg)
+ {
+ /* We found an id-expression, but it was something that we
+ should not have found. This is an error, not something
+ we can recover from, so report the error we found and
+ we'll recover as gracefully as possible. */
+ cp_parser_parse_definitely (parser);
+ cp_parser_error (parser, error_msg);
+ id_expression_or_member_access_p = true;
+ return error_mark_node;
+ }
}
if (expr
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-100482.C b/gcc/testsuite/g++.dg/cpp0x/decltype-100482.C
new file mode 100644
index 0000000..1df8b16
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype-100482.C
@@ -0,0 +1,12 @@
+// PR c++/100482
+// { dg-do compile { target c++11 } }
+
+namespace N {}
+decltype(N) x; // { dg-error "expected primary-expression" }
+
+struct S {};
+decltype(S) y; // { dg-error "argument to .decltype. must be an expression" }
+
+template <typename T>
+struct U {};
+decltype(U) z; // { dg-error "missing template arguments" }