Open PolarLinda6 opened 1 week ago
@llvm/issue-subscribers-clang-frontend
Author: PolarLinda6 (PolarLinda6)
See also https://github.com/llvm/llvm-project/issues/7324. The code above is seemingly supposed to be ill-formed, and we reject it by design.
See also #7324. The code above is seemingly supposed to be ill-formed, and we reject it by design. See also #7324. The code above is seemingly supposed to be ill-formed, and we reject it by design.
The above define_func is indeed bad and unhealthy. However, I think it is incorrect to prompt for redefinition when there is only one definition.
When using non-function templates, the behavior is normal, see the following example, (I don't think function templates are any more special than non-function templates)
The following code compiles successfully
void func();
template<typename>
struct define_func {
friend void func() {}
};
auto main() -> int {
[[maybe_unused]] define_func<int> _{};
}
The following code failed to compile, indicating a redefinition
void func();
template<typename>
struct define_func {
friend void func() {}
};
auto main() -> int {
[[maybe_unused]] define_func<int> _{};
[[maybe_unused]] define_func<double> __{};
}
And interesting enough that, if we somehow referenced the template parameter in the friend declaration, then clang would accept it:
https://godbolt.org/z/Kjx7GKsqM
and clearly we reject the case from CWG2174:
https://godbolt.org/z/ETdY7Yzh4
@cor3ntin @erichkeane do you have any thoughts?
error message:
Additional Information:
Version: clang version 18.1.8 Link: godbolt
PS: The code compiles successfully on gcc and msvc.