]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: friend vs inherited guide confusion [PR117855]
authorPatrick Palka <ppalka@redhat.com>
Tue, 28 Jan 2025 14:27:02 +0000 (09:27 -0500)
committerPatrick Palka <ppalka@redhat.com>
Tue, 28 Jan 2025 14:27:02 +0000 (09:27 -0500)
We recently started using the lang_decl_fn::context field to track
inheritedness of a deduction guide (for C++23 inherited CTAD).  This
new overloading of the field accidentally made DECL_FRIEND_CONTEXT
return non-NULL for inherited guides, which breaks the below testcase
during overload resolution with an inherited guide.

This patch fixes this by refining DECL_FRIEND_CONTEXT appropriately.

PR c++/117855

gcc/cp/ChangeLog:

* cp-tree.h (DECL_FRIEND_CONTEXT): Exclude deduction guides.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/class-deduction-inherited7.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/testsuite/g++.dg/cpp23/class-deduction-inherited7.C [new file with mode: 0644]

index d3c573f064a367c6c52212ff422066a57645c840..7bf95571bf655938832451a075cf3e1035f20a2a 100644 (file)
@@ -3635,7 +3635,8 @@ struct GTY(()) lang_decl {
    the DECL_FRIEND_CONTEXT for `f' will be `S'.  */
 #define DECL_FRIEND_CONTEXT(NODE)                              \
   ((DECL_DECLARES_FUNCTION_P (NODE) && !DECL_VIRTUAL_P (NODE)  \
-    && !DECL_CONSTRUCTOR_P (NODE))                             \
+    && !DECL_CONSTRUCTOR_P (NODE)                              \
+    && (cxx_dialect < cxx23 || !deduction_guide_p (NODE)))     \
    ? LANG_DECL_FN_CHECK (NODE)->context                                \
    : NULL_TREE)
 
diff --git a/gcc/testsuite/g++.dg/cpp23/class-deduction-inherited7.C b/gcc/testsuite/g++.dg/cpp23/class-deduction-inherited7.C
new file mode 100644 (file)
index 0000000..b1d5e89
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/117855
+// { dg-do compile { target c++20 } }
+
+template <typename T, int _Extent = -1> struct span { span(T&&);};
+template <typename T> span(T &&) -> span<T>;
+template <typename et, int e = -1>
+struct this_span : span<et, e> {
+  using span<et, e>::span;
+};
+template <typename T> this_span(T &&) -> this_span<T>;
+int vec;
+this_span a = vec;