From: Patrick Palka Date: Tue, 28 Jan 2025 14:27:02 +0000 (-0500) Subject: c++: friend vs inherited guide confusion [PR117855] X-Git-Tag: releases/gcc-14.3.0~543 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c061ad5a36ba0c07d3d9d82a85aebb887def759d;p=thirdparty%2Fgcc.git c++: friend vs inherited guide confusion [PR117855] 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 (cherry picked from commit ea578dd251eaf6304b0c95acc107f9a4d63bee8f) --- diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ab2b0904ed60..a9a4a7abc40d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3575,7 +3575,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 index 000000000000..b1d5e89ad021 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/class-deduction-inherited7.C @@ -0,0 +1,12 @@ +// PR c++/117855 +// { dg-do compile { target c++20 } } + +template struct span { span(T&&);}; +template span(T &&) -> span; +template +struct this_span : span { + using span::span; +}; +template this_span(T &&) -> this_span; +int vec; +this_span a = vec;