+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.
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,
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))
{
/* 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);
}
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
--- /dev/null
+// 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 "" }
+}