Bug 57764 - class static constexpr variables cannot be references
Summary: class static constexpr variables cannot be references
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2013-06-30 22:56 UTC by Eric Niebler
Modified: 2014-08-29 12:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-07-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Niebler 2013-06-30 22:56:37 UTC
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
Comment 1 Daniel Krügler 2013-07-01 18:32:08 UTC
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.
Comment 2 Paolo Carlini 2014-08-29 12:44:56 UTC
This is fixed in 4.9.0 and mainline. I'm adding the testcase and closing the bug.
Comment 3 paolo@gcc.gnu.org 2014-08-29 12:47:50 UTC
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
Comment 4 Paolo Carlini 2014-08-29 12:49:25 UTC
Done.