constexpr int x = 42; struct S { static constexpr int const & y = x; }; constexpr int const & S::y; ... gives: $ /usr/local/gcc-4.8/bin/g++ -std=gnu++11 -c main.cpp main.cpp:12:38: error: non-constant in-class initialization invalid for static member ‘S::y’ static constexpr int const & y = x; ^ main.cpp:12:38: error: (an out of class initialization is required) main.cpp:12:38: error: ‘S::y’ cannot be initialized by a non-constant expression when being declared
The problem indeed seems to occur for static data members only and it occurs, if the referenced variable is usable in integral constant expressions, such as when declared as const int x = 42; or constexpr int x = 42; The problem exists for gcc 4.9.0 trunk as well.
This is fixed in 4.9.0 and mainline. I'm adding the testcase and closing the bug.
Author: paolo Date: Fri Aug 29 12:47:19 2014 New Revision: 214728 URL: https://gcc.gnu.org/viewcvs?rev=214728&root=gcc&view=rev Log: 2014-08-29 Paolo Carlini <paolo.carlini@oracle.com> PR c++/57764 * g++.dg/cpp0x/constexpr-57764.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-57764.C Modified: trunk/gcc/testsuite/ChangeLog
Done.