不使用时实例化static const和static constexpr成员变量

问题描述 投票:0回答:0

在下面的示例中,我有一个带有

static const
static constexpr
成员变量的类模板。

template <class T>
struct S {                                      // MSVC: clang:
    static const     bool value1 = T::value1;   // error error
    static constexpr bool value2 = T::value2;   // error OK
};

S<void> s;

S<void>
中的成员变量有语法错误,但没有被使用。 MSVC 和 clang 不同意是否诊断错误。查看代码中的注释。 现场演示.

哪个编译器是正确的?

c++ templates c++20 constexpr
© www.soinside.com 2019 - 2024. All rights reserved.