This patch fixes an "unguarded" call to coerce_template_parms in
build_standard_check: processing_template_decl could be zero if we
get here during processing of the first 'auto' parameter of an
abbreviated function template, or if we're processing the type
constraint of a non-templated variable. In the testcase below, this
leads to an ICE when coerce_template_parms instantiates C's dependent
default template argument.
gcc/cp/ChangeLog:
PR c++/97052
* constraint.cc (build_type_constraint): Temporarily increment
processing_template_decl before calling build_concept_check.
* pt.c (make_constrained_placeholder_type): Likewise.
gcc/testsuite/ChangeLog:
PR c++/97052
* g++.dg/cpp2a/concepts-defarg2.C: New test.
build_type_constraint (tree decl, tree args, tsubst_flags_t complain)
{
tree wildcard = build_nt (WILDCARD_DECL);
+ ++processing_template_decl;
tree check = build_concept_check (decl, wildcard, args, complain);
+ --processing_template_decl;
if (check == error_mark_node)
return error_mark_node;
return unpack_concept_check (check);
tree expr = tmpl;
if (TREE_CODE (con) == FUNCTION_DECL)
expr = ovl_make (tmpl);
+ ++processing_template_decl;
expr = build_concept_check (expr, type, args, tf_warning_or_error);
+ --processing_template_decl;
PLACEHOLDER_TYPE_CONSTRAINTS (type) = expr;
--- /dev/null
+// PR c++/97052
+// { dg-do compile { target c++20 } }
+
+template<typename T, typename U = typename T::type>
+concept C = true;
+
+constexpr bool f(C auto) {
+ return true;
+}
+
+static_assert(f(0));
+
+C auto x = 0;