-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Modules] "Cannot befriend target of using declaration" #61125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-modules |
@llvm/issue-subscribers-c-1 Author: David Stone (davidstone)
Given the following two translation units
module;
namespace n
{
template<typename>
struct a {
template<typename T>
friend void aa(a<T>);
};
template<typename T>
inline void aa(a<T>) {
}
} //namespace n
export module a;
namespace n {
export using n::a;
export using n::aa;
} import a;
void b() {
aa(n::a<int>());
} And compiling with clang++ -std=c++20 -x c++-module --precompile -c a.cpp -o a.pcm
clang++ -w -std=c++20 -fmodule-file=a=a.pcm -c b.cpp -o /dev/null Causes clang to error with In file included from b.cpp:1:
a.cpp:9:14: error: cannot befriend target of using declaration
friend void aa(a<T>);
^
b.cpp:4:5: note: in instantiation of template class 'n::a<int>' requested here
aa(n::a<int>());
^
a.cpp:13:13: note: target of using declaration
inline void aa(a<T>) {
^
a.cpp:24:17: note: using declaration
export using n::aa;
^
1 error generated. I believe this code should be accepted, but I'm not 100% sure. |
@davidstone @cor3ntin @AaronBallman @shafik I am not sure about the root reason for the error. (which seems not related to modules) So I tried to CC other guys. What's the purpose of |
Those changes came in from c70fca60dab47 back in 2013. The explanation in https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20130325/076977.html is that [dcl.meaning]p1 is the reason:
Those words are no longer present, I think we hit this case instead: https://eel.is/c++draft/dcl.meaning#general-2.3. I didn't track down what changed the wording, but that wording is present in C++20, but not C++23. If I had to hazard a guess, I would guess the words changed thanks to "declarations and where to find them" (https://wg21.link/P1787) which @Endilll is quite familiar with. |
Thanks! I took another look and now I feel this is more or less a mismatch. The code is: llvm-project/clang/lib/Sema/SemaDecl.cpp Lines 3600 to 3609 in f69e267
Here the story is, during the compilation of This is the reason why it won't happen in normal codes, since in normal codes, in the reproducer, we will always see the actual function decl first and later the using decl. Let me see how can we fix this. |
Oh, when I try to work on this, I surprisingly find the reproducer is accepted now... I commit it directly to avoid regression at 2d81994 Feel free to ask for reopening this if I observe anything wrong. |
@ChuanqiXu9 Does whatever change cause this issue to be fixed also fix #138558? |
I didn't search the commit that makes this issue closed. But #138558 is different than the current one. I feel from what @AaronBallman said, the friend declaration won't be looked up. Since in the current issue, there is a declaration We can see it clearly from the non modular example: https://godbolt.org/z/45jsr61WM So... we can't fix it since it is not an "issue" |
Let me move the discussion to #138558. |
Given the following two translation units
And compiling with
Causes clang to error with
I believe this code should be accepted, but I'm not 100% sure.
The text was updated successfully, but these errors were encountered: