llvm-project/clang/test/Modules/befriend-3.cppm
Chuanqi Xu ab5a5a90c0 [C++20] [Modules] Fix incorrect diagnostic for using befriend target
Close https://github.com/llvm/llvm-project/issues/138558

The compiler failed to understand the redeclaration-relationship when
performing checks when MergeFunctionDecl. This seemed to be a complex
circular problem (how can we know the redeclaration relationship before
performing merging?). But the fix seems to be easy and safe. It is fine
to only perform the check only if the using decl is a local decl.
2025-08-14 14:23:14 +08:00

20 lines
829 B
C++

// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify
export module m;
namespace test {
namespace ns1 {
namespace ns2 {
template<class T> void f(T t); // expected-note {{target of using declaration}}
}
using ns2::f; // expected-note {{using declaration}}
}
struct A { void f(); }; // expected-note 2{{target of using declaration}}
struct B : public A { using A::f; }; // expected-note {{using declaration}}
template<typename T> struct C : A { using A::f; }; // expected-note {{using declaration}}
struct X {
template<class T> friend void ns1::f(T t); // expected-error {{cannot befriend target of using declaration}}
friend void B::f(); // expected-error {{cannot befriend target of using declaration}}
friend void C<int>::f(); // expected-error {{cannot befriend target of using declaration}}
};
}