Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
Here we are emitting a bogus error in get_reflection because it
got something for which is_auto was true: the constrained auto
coming from make_constrained_auto. We represent the
return-type-requirement as a constrained auto which is in fact
a placeholder, but in this case we don't want the error. In the PR
Jason suggested doing something to obscure the placeholderness
across the call to build_concept_check. I think we could rewrite
the identifier for the build_concept_check call.
PR c++/124457
gcc/cp/ChangeLog:
* cp-tree.h (make_generic_type_name): Declare.
* parser.cc (make_generic_type_name): No longer static.
* pt.cc (make_constrained_placeholder_type): Use
make_generic_type_name to temporarily obfuscate the name.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/concept1.C: New test.
---
gcc/cp/cp-tree.h | 1 +
gcc/cp/parser.cc | 2 +-
gcc/cp/pt.cc | 5 +++++
gcc/testsuite/g++.dg/reflect/concept1.C | 14 ++++++++++++++
4 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/reflect/concept1.C
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ea3cb049785..333dc56551a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -8046,6 +8046,7 @@ extern bool literal_integer_zerop (const_tree);
extern tree attr_chainon (tree, tree);
extern tree maybe_add_dummy_lambda_op (tree);
extern void remove_dummy_lambda_op (tree, tree);
+extern tree make_generic_type_name ();
/* in pt.cc */
extern tree canonical_type_parameter (tree);
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 8d88dc9c312..f7e254e8f7c 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -57485,7 +57485,7 @@ c_parse_file (void)
template parameter implied by `auto' or a concept identifier). */
static GTY(()) int generic_parm_count;
-static tree
+tree
make_generic_type_name ()
{
char buf[32];
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 020a70c1112..b4ba7d150e0 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -30941,7 +30941,12 @@ make_constrained_placeholder_type (tree type, tree
con, tree args)
/* Build the constraint. */
tree tmpl = DECL_TI_TEMPLATE (con);
++processing_template_decl;
+ tree old_name = TYPE_IDENTIFIER (type);
+ /* Temporarily obfuscate the name so that we don't emit the "placeholder
+ type" error when taking the reflection of this constrained auto. */
+ TYPE_IDENTIFIER (type) = make_generic_type_name ();
tree expr = build_concept_check (tmpl, type, args, tf_warning_or_error);
+ TYPE_IDENTIFIER (type) = old_name;
--processing_template_decl;
PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type)
diff --git a/gcc/testsuite/g++.dg/reflect/concept1.C
b/gcc/testsuite/g++.dg/reflect/concept1.C
new file mode 100644
index 00000000000..88121f20d01
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/concept1.C
@@ -0,0 +1,14 @@
+// PR c++/124457
+// { dg-do compile { target c++26 }
+// { dg-additional-options "-freflection" }
+
+template <class T, auto t = ^^T>
+concept True = true;
+
+template <class T>
+concept AlsoTrue = requires (T t) {
+ { t } -> True;
+};
+void f1(True auto x);
+template <True T> void f2(T );
+auto f3(int) -> True auto;
base-commit: 2c1a819254cc892877014169f99edce7eaced66f
--
2.53.0