Ala*_*lan 5 c++ language-lawyer c++20
我编写了以下程序,该程序使用 msvc 编译,但不使用 gcc 和 clang 编译。演示
template<int x>
struct X {
consteval static int get();
int f() const;
};
//compiles with msvc but not with gcc and clang
template<int x> int X<x>::get(){ return x; }
int main() {
constexpr int i = X<4>::get();
}
Run Code Online (Sandbox Code Playgroud)
正如我们所看到的,MSVC 编译了上面的演示,而 GCC 和 Clang 拒绝了它。海湾合作委员会 说:
template<int x>
struct X {
consteval static int get();
int f() const;
};
//compiles with msvc but not with gcc and clang
template<int x> int X<x>::get(){ return x; }
int main() {
constexpr int i = X<4>::get();
}
Run Code Online (Sandbox Code Playgroud)
我想知道根据 C++20 标准,哪个编译器在这里是正确的。