[Bug c++/122550] [14 Regression] constrained hidden template friend alongside existing declaration is ambiguous
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 30 14:25:16 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122550
--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:c32eced174e425483478364e09f1aa2d80b0a7b5
commit r14-12489-gc32eced174e425483478364e09f1aa2d80b0a7b5
Author: Egas Ribeiro <egas.g.ribeiro@gmail.com>
Date: Fri Dec 19 21:34:55 2025 +0000
c++: Fix member-like friend detection for non-template classes [PR122550]
member_like_constrained_friend_p was incorrectly returning true for
constrained friend function templates declared in non-template classes,
causing them to be treated as distinct from their forward declarations.
This led to ambiguity errors at call sites.
Per [temp.friend]/9, a constrained friend is only "member-like" (and thus
declares a different function) in two cases:
1. Non-template friends with constraints (must be in a templated class)
2. Template friends whose constraints depend on outer template parameters
In both cases, the enclosing class scope must be templated. The fix adds
a check for CLASSTYPE_IMPLICIT_INSTANTIATION to ensure the friend's
context is actually a class template, not a plain class or explicit
specialization.
PR c++/122550
gcc/cp/ChangeLog:
* decl.cc (member_like_constrained_friend_p): Check that the
friend's enclosing class is an implicit instantiation.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-friend18.C: New test.
* g++.dg/cpp2a/concepts-friend18a.C: New test.
Signed-off-by: Egas Ribeiro <egas.g.ribeiro@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
(cherry picked from commit 3f09320bf65312a2f442aca514a35a382a6521f1)
More information about the Gcc-bugs
mailing list