We currently fail upon the following because an assert in dependent_type_p fails for f's parameter
=== cut here === consteval int id (int i) { return i; } constexpr int f (auto i) requires requires { id (i) } { return i; } void g () { f (42); } === cut here === This patch fixes this by handling synthesized parameters for abbreviated function templates in that assert. Successfully tested on x86_64-pc-linux-gnu. PR c++/111106 gcc/cp/ChangeLog: * pt.cc (dependent_type_p): Relax assert to handle synthesized template parameters when !processing_template_decl. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/consteval37.C: New test. --- gcc/cp/pt.cc | 6 +++++- gcc/testsuite/g++.dg/cpp2a/consteval37.C | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval37.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index dfce1b3c359..a50d5cfd5a2 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -28019,7 +28019,11 @@ dependent_type_p (tree type) /* If we are not processing a template, then nobody should be providing us with a dependent type. */ gcc_assert (type); - gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type)); + gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type) + || (/* Synthesized template parameter */ + DECL_TEMPLATE_PARM_P (TEMPLATE_TYPE_DECL (type)) && + (DECL_IMPLICIT_TEMPLATE_PARM_P + (TEMPLATE_TYPE_DECL (type))))); return false; } diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval37.C b/gcc/testsuite/g++.dg/cpp2a/consteval37.C new file mode 100644 index 00000000000..ea2641fc204 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/consteval37.C @@ -0,0 +1,19 @@ +// PR c++/111106 +// { dg-do compile { target c++20 } } + +consteval int id (int i) { return i; } + +constexpr int f (auto i) // { dg-line line_1 } + requires requires { id (i) } // { dg-error "expected|invalid use" } +{ + return i; +} + +void g () { + f (42); // { dg-error "parameter 1" } +} + +// { dg-error "constraints on a non-templated" {} { target *-*-* } line_1 } +// { dg-error "has incomplete type" {} { target *-*-* } line_1 } +// { dg-error "invalid type for" {} { target *-*-* } line_1 } +// { dg-note "declared here" {} { target *-*-* } line_1 } -- 2.44.0