在下面的代码struct A
中具有立即函数默认构造函数,并且在动态内存中创建结构的对象是指new A{}
:
struct A {
consteval A() {}
};
int main() {
new A{};
}
只有 Clang 接受它。
海合会抱怨
error: the value of '<anonymous>' is not usable in a constant expression
6 | new A{};
| ^
note: '<anonymous>' was not declared 'constexpr'
MSVC 也是如此:
error C7595: 'A::A': call to immediate function is not a constant expression
演示:https ://gcc.godbolt.org/z/6Px5WYGzd
哪个编译器在这里?