[cfe-dev] clang issue with 'mutable' ?

Jonathan Sauer jonathan.sauer at gmx.de
Mon Oct 21 10:07:44 PDT 2013


Hello,

>   template <typename T>
>   struct wrapper
>   {
>     wrapper() : member() {}
>     mutable T member;
>   };
> 
>   int main()
>   {
>     wrapper<int const> w;
>   }
> 
> clang would raise the error "'mutable' and 'const' cannot be mixed",
> while the same compiles (and works !) fine with g++.
> 
> (Please note that the above may not look very meaningful, but in the
> original case I extracted this from it definitely does :-) )
> 
> Could someone please confirm that this is a clang bug, or otherwise
> explain if it is indeed illegal C++ ?

C++11 ยง7.1.1p10 says:

| The mutable specifier can be applied only to names of class data members (9.2) and cannot be
| applied to names declared const or static, and cannot be applied to reference members.

With the example of:

| class X {
|   mutable const int* p; // OK
|   mutable int* const q; // ill-formed
| };

So I'd say both clang and gcc ToT are correct to reject it.


HTH,
Jonathan





More information about the cfe-dev mailing list