Bug 54086

Summary: GCC should allow constexpr and const together
Product: gcc Reporter: Stephen <steveire>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: daniel.kruegler, jason
Priority: P3    
Version: 4.6.1   
Target Milestone: 4.7.2   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Stephen 2012-07-24 15:47:35 UTC
GCC and Clang differ in how they handle this code. Clang compiles it, but GCC does not:

#include <iostream>

static constexpr const char Data[] = {
  'D', 'A', 'T', 'A',
};
static constexpr const char *data_func() { return Data; }

int main(int argc, char **argv)
{

  char c = 'T';

  switch(c)
  {
    case *data_func():
      std::cout << "GOT A D" << std::endl;
      break;
    case *(data_func() + 2):
      std::cout << "GOT A T" << std::endl;
  }
}



$ clang++ --version
clang version 3.2 
Target: x86_64-unknown-linux-gnu
Thread model: posix

$ g++ -dumpversion
4.6.1

$ g++ main.cpp -std=c++0x
main.cpp:163:48: error: both ‘const’ and ‘constexpr’ cannot be used here


http://thread.gmane.org/gmane.comp.compilers.clang.devel/22984 

Thanks,
Comment 1 Paolo Carlini 2012-07-24 22:19:29 UTC
Changing this behavior should be pretty simple, if we want. Jason, shall we do that? PS: volatile constexpr?!?
Comment 2 Jason Merrill 2012-07-25 14:57:11 UTC
Author: jason
Date: Wed Jul 25 14:57:06 2012
New Revision: 189852

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189852
Log:
	PR c++/54086
	* decl.c (grokdeclarator): Allow const and constexpr together.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-const1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-object1.C
Comment 3 Jason Merrill 2012-07-25 15:22:02 UTC
Fixed for 4.8.
Comment 4 Jason Merrill 2012-09-10 14:24:04 UTC
Author: jason
Date: Mon Sep 10 14:23:54 2012
New Revision: 191144

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191144
Log:
	PR c++/54086
	* decl.c (grokdeclarator): Allow const and constexpr together.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-const1.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/decl.c
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-object1.C
Comment 5 Jason Merrill 2012-09-10 14:44:54 UTC
Fixed for 4.7.2 as well.