[cfe-dev] clang vs GCC error case: both ‘const’ and ‘constexpr’ cannot be used here

Richard Smith richard at metafoo.co.uk
Mon Jul 23 10:59:37 PDT 2012


On Mon, Jul 23, 2012 at 8:39 AM, Jordan Rose <jordan_rose at apple.com> wrote:

> [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).
>

Yes, I came to the same conclusion. [dcl.type]p2 is talking only about the
type-specifiers which appear in the decl-specifier-seq. [dcl.constexpr]p9
is clearly not saying we should act as if 'const' appeared in the
decl-specifier-seq, since in this case, the constexpr implies a const on p,
not on *p:

constexpr const char *p = 0;

The relevant rule seems to be [dcl.type.cv]p1: "Redundant cv-qualifications
are ignored."

Hence I believe this is a GCC bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120723/9631d629/attachment.html>


More information about the cfe-dev mailing list