[Bug c++/60430] New: static_assert and reference to const/constexpr

florent.hivert at lri dot fr gcc-bugzilla@gcc.gnu.org
Wed Mar 5 16:08:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60430

            Bug ID: 60430
           Summary: static_assert and reference to const/constexpr
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: florent.hivert at lri dot fr

I think the following should be accepted:


constexpr const int A = 42;
const int &B = A;
static_assert(&A == &B, "Bug");

int main() {return 0;}


Indeed, even if B is not constexpr its address is. On the contrary GCC
complains with


bug2.cpp:3:1: error: non-constant condition for static assertion
 static_assert(&A == &B, "Bug");
 ^
bug2.cpp:3:1: error: the value of ‘B’ is not usable in a constant expression
bug2.cpp:2:12: note: ‘B’ was not declared ‘constexpr’
 const int &B = A;


More information about the Gcc-bugs mailing list