相关疑难解决方法(0)

在默认模板参数中调用constexpr

在C++ 11中,我使用constexpr函数作为模板参数的默认值 - 它看起来像这样:

template <int value>
struct bar
{
    static constexpr int get()
    {
        return value;
    }
};

template <typename A, int value = A::get()>
struct foo
{
};

int main()
{
    typedef foo<bar<0>> type;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

G ++ 4.5和4.7编译它,但Clang ++ 3.1没有.来自clang的错误消息是:

clang_test.cpp:10:35: error: non-type template argument is not a constant expression
template <typename A, int value = A::get()>
                                  ^~~~~~~~
clang_test.cpp:17:19: note: while checking a default template argument used here
        typedef foo<bar<3>> type;
                ~~~~~~~~~^~
clang_test.cpp:10:35: note: undefined function …
Run Code Online (Sandbox Code Playgroud)

c++ gcc clang constexpr c++11

12
推荐指数
1
解决办法
2017
查看次数

标签 统计

c++ ×1

c++11 ×1

clang ×1

constexpr ×1

gcc ×1