Bug 58541 - [c++11] Bogus "error: redeclaration ... differs in ‘constexpr’"
Summary: [c++11] Bogus "error: redeclaration ... differs in ‘constexpr’"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2013-09-26 05:38 UTC by Paul Pluzhnikov
Modified: 2017-06-14 09:20 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.9.3, 5.3.0, 6.1.0, 7.0
Last reconfirmed: 2016-05-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2013-09-26 05:38:03 UTC
Test:

struct X {
 static constexpr const char x[] = "x";
};
const char X::x[];

Using g++ (GCC) 4.9.0 20130923 (experimental):

g++ -c t.cc -std=c++11
t.cc:4:17: error: redeclaration 'X::x' differs in 'constexpr'
 const char X::x[];
                 ^
t.cc:2:30: error: from previous declaration 'X::x'
  static constexpr const char x[] = "x";
                              ^
t.cc:4:17: error: declaration of 'constexpr const char X::x [2]' outside of class is not definition [-fpermissive]
 const char X::x[];
                 ^

Richard Smith says:

  There is no rule requiring successive declarations of variables to agree in 'constexpr'ness (this rule only applies to functions).


Google ref: b/10930205
Comment 1 Martin Sebor 2016-05-13 03:42:31 UTC
Confirmed.  There is no requirement that the namespace-scope definition of a static constexpr class member say its constexpr.  Today's trunk (7.0) fails with the following error.  All supported versions of GCC fail to compile the test case.  If I'm reading the logs right, the error was introduced in r166013.

$ cat xx.cpp && gcc -S -Wall -Wextra -Wpedantic -o/dev/null -std=c++11 xx.cpp
struct X {
  static constexpr const char x[] = "x";
};

const char X::x[];

xx.cpp:5:17: error: ‘constexpr’ needed for in-class initialization of static data member ‘const char X::x [2]’ of non-integral type [-fpermissive]
 const char X::x[];
                 ^
Comment 2 Paolo Carlini 2017-06-14 09:11:35 UTC
This is fixed in 7.1.0. I'm adding a testcase and closing the bug.
Comment 3 paolo@gcc.gnu.org 2017-06-14 09:19:28 UTC
Author: paolo
Date: Wed Jun 14 09:18:57 2017
New Revision: 249186

URL: https://gcc.gnu.org/viewcvs?rev=249186&root=gcc&view=rev
Log:
2017-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58541
	* g++.dg/cpp0x/constexpr-58541.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-58541.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2017-06-14 09:20:02 UTC
Done.