aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2024-07-17 11:08:35 -0400
committerPatrick Palka <ppalka@redhat.com>2024-07-17 11:08:35 -0400
commit247335823f420eb1dd56f4bf32ac78d441f5ccc2 (patch)
tree2e3569e13552fa1c485b9a502372be50f69c7513
parentdb3c8c9726d0bafbb9f85b6d7027fe83602643e7 (diff)
downloadgcc-247335823f420eb1dd56f4bf32ac78d441f5ccc2.zip
gcc-247335823f420eb1dd56f4bf32ac78d441f5ccc2.tar.gz
gcc-247335823f420eb1dd56f4bf32ac78d441f5ccc2.tar.bz2
c++: constrained partial spec type context [PR111890]
maybe_new_partial_specialization wasn't propagating TYPE_CONTEXT when creating a new class type corresponding to a constrained partial spec, which do_friend relies on via template_class_depth to distinguish a template friend from a non-template friend, and so in the below testcase we were incorrectly instantiating the non-template operator+ as if it were a template leading to an ICE. PR c++/111890 gcc/cp/ChangeLog: * pt.cc (maybe_new_partial_specialization): Propagate TYPE_CONTEXT to the newly created partial specialization. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-partial-spec15.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r--gcc/cp/pt.cc1
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C20
2 files changed, 21 insertions, 0 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 4d72ff6..0620c8c 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -992,6 +992,7 @@ maybe_new_partial_specialization (tree& type)
tree t = make_class_type (TREE_CODE (type));
CLASSTYPE_DECLARED_CLASS (t) = CLASSTYPE_DECLARED_CLASS (type);
SET_TYPE_TEMPLATE_INFO (t, build_template_info (tmpl, args));
+ TYPE_CONTEXT (t) = TYPE_CONTEXT (type);
/* We only need a separate type node for storing the definition of this
partial specialization; uses of S<T*> are unconstrained, so all are
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C
new file mode 100644
index 0000000..ad01a39
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C
@@ -0,0 +1,20 @@
+// PR c++/111890
+// { dg-do compile { target c++20 } }
+
+template<class>
+struct A {
+ template<class T>
+ struct B { };
+
+ template<class T> requires T::value
+ struct B<T> { };
+
+ template<class T> requires (sizeof(T) == sizeof(int))
+ struct B<T> {
+ friend void operator+(B&, int) { }
+ };
+};
+
+void f(A<int>::B<int> b) {
+ b + 0;
+}