【发布时间】:2021-04-01 12:53:17
【问题描述】:
g++ 很乐意接受以下代码,而 clang 和 msvc 都能够匹配行外定义。
知道为什么吗?
template <bool B>
struct test
{
test() requires (B);
test() requires(!B);
};
template <>
test<true>::test()
{}
template <>
test<false>::test()
{}
int main()
{
test<false> a;
test<true> b;
return 0;
}
叮当声:
错误:“
test”的行外定义与“test<true>”中的任何声明都不匹配
Msvc:
错误 C2244:'
test<true>::test':无法将函数定义与现有声明匹配
【问题讨论】:
-
我很想说你不需要约束,因为无论如何你都在专门化构造函数。
标签: c++ constructor require c++20