Clang vs gcc CRTP: constexpr variable cannot be of non-liberal type

I have a CRTP template class:

template <typename S>
class Base
{
    public:
    constexpr static S NOT_SET{0};
};

struct Derived : public Base<Derived>
{
};

Clang (5.0.0) does not accept this:

5 : <source>:5:24: error: constexpr variable cannot have non-literal type 'const Derived'
    constexpr static S NOT_SET{0};
                       ^
8 : <source>:8:25: note: in instantiation of template class 'Base<Derived>' requested here
struct Derived : public Base<Derived>
                        ^
5 : <source>:5:24: note: incomplete type 'const Derived' is not a literal type
    constexpr static S NOT_SET{0};
                       ^
8 : <source>:8:8: note: definition of 'Derived' is not complete until the closing '}'
struct Derived : public Base<Derived>
       ^
1 error generated.
Compiler exited with result code 1

But gcc (tested on 4.9.2 and 6.2) accepts it just fine.

How to do this in clang?

+2
source share
1 answer

Derived Base, . , , . .
, } ( , , , -).
, ( ):

( ) } .
- , , noexcept-specificiers ( ).
.

, clang , .


, . , (, ) constexpr , constexpr , ( ).

+2

Source: https://habr.com/ru/post/1687711/


All Articles