Vincent
Vincent

Reputation: 60341

Constexpr construction and static member is not working

Consider the following code:

#include <iostream>
#include <type_traits>

template<typename Type>
class Test
{
    public:
        constexpr Test(const Type val) : _value(val) {}
        constexpr Type get() const {return _value;}
        static void test()
        {
            static constexpr Test<int> x(42);
            std::integral_constant<int, x.get()> i;
            std::cout<<i<<std::endl;
        }
    protected:
        Type _value;
};

int main(int argc, char *argv[])
{
    Test<double>::test();
    return 0;
}

Under g++ 4.7.1, it returns the error:

main.cpp: In static member function ‘static void Test<Type>::test()’:
main.cpp:13:48: error: invalid use of ‘Test<Type>::get<int>’ to form a pointer-to-member-function
main.cpp:13:48: note:   a qualified-id is required
main.cpp:13:48: error: could not convert template argument ‘x.Test<Type>::get<int>()’ to ‘int’
main.cpp:13:51: error: invalid type in declaration before ‘;’ token

I do not understand the problem: is it a compiler bug or is it a real problem ? How to solve it ?

Upvotes: 1

Views: 351

Answers (1)

Karthik T
Karthik T

Reputation: 31952

It looks like a GCC bug, clang 3.2 compiles without any error

Upvotes: 1

Related Questions