aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2017-06-23 19:29:51 -0400
committerJason Merrill <jason@gcc.gnu.org>2017-06-23 19:29:51 -0400
commite2e80f2f3c05ebc80ed0489babe527468a99e5a1 (patch)
tree89321169b9afe369809cbf60b8fd80fbb0a0593a /gcc
parentee444c5f45985c29dcf5b4341f05a0bd15cc1897 (diff)
downloadgcc-e2e80f2f3c05ebc80ed0489babe527468a99e5a1.zip
gcc-e2e80f2f3c05ebc80ed0489babe527468a99e5a1.tar.gz
gcc-e2e80f2f3c05ebc80ed0489babe527468a99e5a1.tar.bz2
PR c++/79056 - C++17 ICE with invalid template syntax.
* parser.c (cp_parser_simple_type_specifier): Don't assume that type is a TYPE_DECL. (cp_parser_check_for_invalid_template_id): Handle TYPE_DECL. * pt.c (template_placeholder_p): New. * cp-tree.h: Declare it. From-SVN: r249614
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/parser.c6
-rw-r--r--gcc/cp/pt.c8
-rw-r--r--gcc/testsuite/g++.dg/parse/template28.C10
5 files changed, 32 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 92f478a..2d590a5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2017-06-23 Jason Merrill <jason@redhat.com>
+
+ PR c++/79056 - C++17 ICE with invalid template syntax.
+ * parser.c (cp_parser_simple_type_specifier): Don't assume that type
+ is a TYPE_DECL.
+ (cp_parser_check_for_invalid_template_id): Handle TYPE_DECL.
+ * pt.c (template_placeholder_p): New.
+ * cp-tree.h: Declare it.
+
2017-06-23 Marc Glisse <marc.glisse@inria.fr>
* decl.c (duplicate_decls): Use builtin_structptr_types.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 40c113b..33dde15 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6413,6 +6413,7 @@ extern void check_template_variable (tree);
extern tree make_auto (void);
extern tree make_decltype_auto (void);
extern tree make_template_placeholder (tree);
+extern bool template_placeholder_p (tree);
extern tree do_auto_deduction (tree, tree, tree);
extern tree do_auto_deduction (tree, tree, tree,
tsubst_flags_t,
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ddb1cf3..97cd923 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2983,7 +2983,9 @@ cp_parser_check_for_invalid_template_id (cp_parser* parser,
if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
{
- if (TYPE_P (type))
+ if (TREE_CODE (type) == TYPE_DECL)
+ type = TREE_TYPE (type);
+ if (TYPE_P (type) && !template_placeholder_p (type))
error_at (location, "%qT is not a template", type);
else if (identifier_p (type))
{
@@ -17060,7 +17062,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
/* There is no valid C++ program where a non-template type is
followed by a "<". That usually indicates that the user
thought that the type was a template. */
- cp_parser_check_for_invalid_template_id (parser, TREE_TYPE (type),
+ cp_parser_check_for_invalid_template_id (parser, type,
none_type,
token->location);
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index fba7fb1..392fba0 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -24799,6 +24799,14 @@ make_template_placeholder (tree tmpl)
return t;
}
+/* True iff T is a C++17 class template deduction placeholder. */
+
+bool
+template_placeholder_p (tree t)
+{
+ return is_auto (t) && CLASS_PLACEHOLDER_TEMPLATE (t);
+}
+
/* Make a "constrained auto" type-specifier. This is an
auto type with constraints that must be associated after
deduction. The constraint is formed from the given
diff --git a/gcc/testsuite/g++.dg/parse/template28.C b/gcc/testsuite/g++.dg/parse/template28.C
new file mode 100644
index 0000000..6868bc8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/template28.C
@@ -0,0 +1,10 @@
+// PR c++/79056
+
+template<class> struct A {};
+
+template<class T> void foo(A<T>=A<T>()) {} // { dg-error "" }
+
+void bar()
+{
+ foo(A<int>()); // { dg-error "" }
+}