我正在用clang 3.3编译一些代码,似乎可以用gcc 4.8编译好:
原始代码是:
template <std::size_t N> struct helper { typedef void type; };
template <> struct helper<64> { typedef int64_t type; };
template <> struct helper<32> { typedef int32_t type; };
template <> struct helper<16> { typedef int16_t type; };
template <> struct helper<8> { typedef int8_t type; };
template <std::size_t I, std::size_t F>
struct test
{
typedef typename helper<I+F>::type value_type;
static constexpr std::size_t frac_mask = ~((~value_type(0)) << F);
};
Run Code Online (Sandbox Code Playgroud)
在clang中,如果我尝试声明test <16,16>或test <8,0>,我会收到错误:
test.cpp:41:34:错误:constexpr变量'frac_mask'必须由常量表达式初始化
Run Code Online (Sandbox Code Playgroud)static constexpr std::size_t frac_mask = …