Files
llvm-project/clang/test/Modules/pr170235.cppm
Chuanqi Xu 93ebe63f2e [C++20] [Modules] Fix ADL for friend in modules
Close https://github.com/llvm/llvm-project/issues/170235

The cause of the issue is it didn't check friendness for decls
in ordinary namespace if it isn't visible.

It is fine for code before modules, since everything is visible.
But it is not true after modules came in. This patch adjusts this.

Note that this doesn't change the control flow for non-modules codes,
as the decls in ordinary namespace is always visible then it won't never
fall in following friendness check.
2025-12-03 10:29:52 +08:00

33 lines
889 B
C++

// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -std=c++20 %t/lib.cppm -emit-module-interface -o %t/lib.pcm
// RUN: %clang_cc1 -std=c++20 %t/main.cpp -fmodule-file=lib=%t/lib.pcm -fsyntax-only -verify
//
// RUN: %clang_cc1 -std=c++20 %t/lib.cppm -emit-reduced-module-interface -o %t/lib.pcm
// RUN: %clang_cc1 -std=c++20 %t/main.cpp -fmodule-file=lib=%t/lib.pcm -fsyntax-only -verify
//--- lib.cppm
export module lib;
namespace lib {
struct A;
// Definition comes BEFORE the class declaration
int foo(const A &, int) { return 42; }
struct A {
// Friend declaration inside the class
friend int foo(const A &, int);
};
export A a{};
}
//--- main.cpp
// expected-no-diagnostics
import lib;
int main() {
// Should be found via ADL since lib::a is of type lib::A
auto res1 = foo(lib::a, 1);
return 0;
}