Ezr*_*ein 5 c++ templates clang c++20
考虑以下创建受概念约束的部分模板特化的代码。
#include <concepts>
template <typename T>
struct Foo { };
template<typename T>
requires std::integral<T>
struct Foo<T> {
static void bar();
};
template<typename T>
requires std::integral<T>
void Foo<T>::bar() { }
int main() {
Foo<int>::bar();
}
Run Code Online (Sandbox Code Playgroud)
此代码使用 gcc 10.2 和 MSVC 19.27 编译没有错误。但是,在 bar() 的外部定义中出现了 clang 11.0 错误:
<source>:13:15: error: requires clause differs in template redeclaration
requires std::integral<T>
^
<source>:3:1: note: previous template declaration is here
template <typename T>
Run Code Online (Sandbox Code Playgroud)
如果将定义内嵌移动到部分特化类中,clang 不会出错。
这是 clang 中的错误还是标准出于某种原因不允许上述代码?
链接到 Godbolt 中的代码:https ://godbolt.org/z/orsWaP