[cfe-dev] clang vs GCC error case: both ‘const’ and ‘constexpr’ cannot be used here
Jordan Rose
jordan_rose at apple.com
Mon Jul 23 08:39:46 PDT 2012
[dcl.constexpr]p9: A constexpr specifier used in an object declaration declares the object as const.
[dcl.type]p2: const can be combined with any type specifier except itself.
I could see how GCC could interpret that as meaning "constexpr replaces const", but I think Clang is doing the right thing by allowing both specifiers. The constexpr's "declaring the object as const" is a semantic property, not an implicit inclusion of the const /specifier/.
I'm still not a standardista, though, so someone might have another view (or another citation I missed).
Jordan
On Jul 23, 2012, at 1:34 AM, Stephen Kelly wrote:
>
> Hi there,
>
> clang compiles the following code, 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
>
>
> Which compiler is buggy?
>
> Thanks,
>
> Steve.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list