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,
Changing this behavior should be pretty simple, if we want. Jason, shall we do that? PS: volatile constexpr?!?
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
Fixed for 4.8.
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
Fixed for 4.7.2 as well.