This patch fixes an "unguarded" call to coerce_template_parms in build_standard_check: processing_template_decl could be zero if we we get here during processing of the first 'auto' parameter of an abbreviated function template. In the testcase below, this leads to an ICE when coerce_template_parms substitutes into C's dependent default template argument.
Bootstrapped and regtested on x86_64-pc-linux-gnu and tested by building cmcstl2 and range-v3. Does this look OK for trunk? gcc/cp/ChangeLog: PR c++/97052 * constraint.cc (build_standard_check): Temporarily increment processing_template_decl when calling coerce_template_parms. gcc/testsuite/ChangeLog: PR c++/97052 * g++.dg/cpp2a/concepts-defarg2: New test. --- gcc/cp/constraint.cc | 2 ++ gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d49957a6c4a..da3b2cc7e65 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -1355,7 +1355,9 @@ build_standard_check (tree tmpl, tree args, tsubst_flags_t complain) gcc_assert (standard_concept_p (tmpl)); gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL); tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl)); + ++processing_template_decl; args = coerce_template_parms (parms, args, tmpl, complain); + --processing_template_decl; if (args == error_mark_node) return error_mark_node; return build2 (TEMPLATE_ID_EXPR, boolean_type_node, tmpl, args); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C new file mode 100644 index 00000000000..6c0670e9fd2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C @@ -0,0 +1,9 @@ +// PR c++/97052 +// { dg-do compile { target c++20 } } + +template<typename T, typename U = typename T::type> +concept C = true; + +bool f(C auto) { + return true; +} -- 2.28.0.618.g9bc233ae1c