小编use*_*897的帖子

clang 3.3和constexpr约束

我正在用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'必须由常量表达式初始化

static constexpr std::size_t frac_mask = …
Run Code Online (Sandbox Code Playgroud)

c++ templates clang c++11

5
推荐指数
1
解决办法
990
查看次数

标签 统计

c++ ×1

c++11 ×1

clang ×1

templates ×1