문제

Given

struct X {};

constexpr auto x = X{};

struct S {
    static constexpr auto& rx = x;  
};

gcc 4.8 says

error: non-constant in-class initialization invalid for static member 'S::rx'

static constexpr auto& rx = x;  
                            ^

error: (an out of class initialization is required)

error: 'S::rx' cannot be initialized by a non-constant expression when being declared

I expect x to be a constant expression, suitable for such initialization. Is this a gcc bug? If not, what is going on here?

올바른 솔루션이 없습니다

다른 팁

This is a bug, and it seems to be already reported.

You may do the below instead:

struct X {};

const auto x = X{};

struct S {
    static constexpr auto& rx = x;  
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top