[英]Is a friend function template defined in the class available for lookup? clang++ and g++ disagree
Here is the code: 这是代码:
struct foo {
template<typename T = void>
friend foo f() { return {}; }
};
int main() {
auto x = f(); // clang++ can't find it, g++ can.
}
clang++ 3.4 gives: clang ++ 3.4给出:
fni2.cpp:8:12: error: use of undeclared identifier 'f'
auto x = f(); // clang++ can't find it, g++ can.
^
1 error generated.
g++ 4.9.0 compiles it, but I don't think it should have. g ++ 4.9.0编译它,但我不认为它应该有。 This is a related question, but there was no definitive answer.
这是一个相关的问题,但没有明确的答案。 Section 15.4.2/2,4 discuss this, but neither of them say anything to suggest that friend function templates defined in-class should have different visibility from non-template friend functions defined in-class.
第15.4.2 / 2,4节讨论了这一点,但他们都没有说任何暗示在类中定义的友元函数模板应该与类中定义的非模板友元函数具有不同的可见性。
This is of academic interest to me only, though it did arise from a question by someone else who may have had an actual use case. 这只是我的学术兴趣,虽然它确实来自其他可能有实际用例的人提出的问题。
It looks like a g++ bug to me. 它看起来像是一个g ++错误。
Yes, this is an error. 是的,这是一个错误。 I'm surprised it's finding the function.
我很惊讶它找到了这个功能。 Apparently GCC fails entirely to hide function templates.
显然GCC完全没有隐藏功能模板。
This C++03 example also compiles, so it could be a regression: 这个C ++ 03示例也编译,所以它可能是一个回归:
struct foo {
template<typename T >
friend void f( T ) { }
};
int main() {
f( 3 ); // clang++ can't find it, g++ can.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.