+2019-03-27 Jason Merrill <jason@redhat.com>
+
+ PR c++/89241 - ICE with lambda in template parameter list.
+ * parser.c (cp_parser_lambda_expression): Also reject a lambda in a
+ template parameter list before C++20.
+ * pt.c (type_dependent_expression_p): True for LAMBDA_EXPR.
+ * semantics.c (begin_class_definition): Restore error about defining
+ non-lambda class in template parm list.
+
2019-03-26 Jason Merrill <jason@redhat.com>
PR c++/86932 - missed SFINAE with empty pack.
}
ok = false;
}
- else if (parser->in_template_argument_list_p)
+ else if (parser->in_template_argument_list_p || processing_template_parmlist)
{
if (!token->error_reported)
{
|| TREE_CODE (expression) == WILDCARD_DECL)
return true;
+ /* A lambda-expression in template context is dependent. dependent_type_p is
+ true for a lambda in the scope of a class or function template, but that
+ doesn't cover all template contexts, like a default template argument. */
+ if (TREE_CODE (expression) == LAMBDA_EXPR)
+ return true;
+
/* A fold expression is type-dependent. */
if (TREE_CODE (expression) == UNARY_LEFT_FOLD_EXPR
|| TREE_CODE (expression) == UNARY_RIGHT_FOLD_EXPR
if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
return error_mark_node;
+ if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
+ {
+ error ("definition of %q#T inside template parameter list", t);
+ return error_mark_node;
+ }
+
/* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
are passed the same as decimal scalar types. */
if (TREE_CODE (t) == RECORD_TYPE
--- /dev/null
+// PR c++/89421
+
+template <int I = []{return 1;}()> // { dg-message "lambda" "" { target c++17_down } }
+struct B
+{
+ static const int i = I;
+};
+
+#if __cplusplus > 201703L
+B<> b;
+static_assert (b.i == 1);
+#endif
--- /dev/null
+// { dg-options "" }
+
+template <int = (struct A{int i;}){42}.i> struct B{}; // { dg-error "" }
+
+B<0> b;