While answering How do I write a lambda expression that looks like a method?, I tried to turn a captureless lambda into a member function pointer by exploiting the fact that, since C++17, captureless lambdas have a constexpr conversion operator to their function pointer type.
So I came up with an issue boiling down to:
template<void(*)()> struct A{};
int main()
{
A<static_cast<void(*)()>([]{})>{}; // 1
constexpr auto fp = static_cast<void(*)()>([]{});
A<fp>{}; // 2
}
Now, this compiles in clang (since 5.0.0) but gcc(>=7.2) complains:
error: lambda-expression in template-argument
A<static_cast<void(*)()>([]{ /*whatever*/ })>{}; // 1
^
error: 'main()::<lambda()>::_FUN' is not a valid template argument for type 'void (*)()' because 'static constexpr void main()::<lambda()>::_FUN()' has no linkage
A<fp>{}; // 2
The question is, who's right?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…