Вызов 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;
}

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 'get' cannot be used in a constant expression
template <typename A, int value = A::get()>
                                  ^
clang_test.cpp:4:23: note: declared here
        static constexpr int get()
                             ^
1 error generated.

Какой из них правильный?

12
задан ildjarn 23 May 2012 в 15:53
поделиться