]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ADL finds all friends (P1787)
authorJason Merrill <jason@redhat.com>
Sat, 1 Nov 2025 18:56:26 +0000 (21:56 +0300)
committerJason Merrill <jason@redhat.com>
Mon, 3 Nov 2025 18:32:26 +0000 (21:32 +0300)
commit8f6c9ebc7d7726596c94f164176b914801c5665c
tree401ebfe4b039d4771c1c9420d957331a9e9eeac7
parent3ce87345084f963ff7ff08abbad8ca0574547ba3
c++: ADL finds all friends (P1787)

Some libstdc++ tests were failing with import std because ADL didn't find
rethrow_exception, even though it's a friend.  The problem turned out to be
because it's not in the same namespace, and in C++17 ADL only makes hidden
friends visible.  But in C++20 P1787 changed [basic.lookup.argdep]/4.2 to
directly include all friends in the lookup.

Note that my change still excludes class members, even though the standard
doesn't specify that; including implicit object member functions would just
break, and even foreign static/xobj member functions seem like they would be
strange to include.

gcc/cp/ChangeLog:

* name-lookup.cc (name_lookup::adl_class_fns): Include all
namespace-scope friends.

gcc/testsuite/ChangeLog:

* g++.dg/lookup/koenig16.C: New test.
gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/lookup/koenig16.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/adl-11_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/adl-11_b.C [new file with mode: 0644]