Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-class static member initialization

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?

like image 642
yuri kilochek Avatar asked Nov 02 '22 05:11

yuri kilochek


1 Answers

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

like image 198
yuri kilochek Avatar answered Nov 15 '22 04:11

yuri kilochek