Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: "Richard Smith" Newsgroups: comp.std.c++ Subject: Defect report: constexpr and mutable members of literal types Date: Wed, 19 Oct 2011 15:23:47 -0700 (PDT) Organization: unknown Lines: 37 Sender: std-cpp-request@vandevoorde.com Approved: stephen.clamage@oracle.com Message-ID: <37522.10.0.7.178.1319061795.squirrel@webmail.secure.aluminati.net> Reply-To: richard@metafoo.co.uk Content-Type: text/plain;charset=iso-8859-1 X-Trace: news.albasani.net 5LsjHYeX+RHVqOVY1S3QK7e1rn0GNCnPshkcJFjobR/R0gk4zDM7RS4/V+gXyk114S7HgLX8Q/+G0r/NYHp99w== NNTP-Posting-Date: Wed, 19 Oct 2011 22:23:50 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="F85z+0dF3DSrJ96FNq6yOYlmDb7XE4GRqPYQBLESsjXDQOveWpruTV6InrIrnmZy0RuTkpIeyxzTXvFmOxDxZc3n37FEXLRgxE4hBaQu0i/EfMJF0n8PM19LKve3rlLh"; mail-complaints-to="abuse@albasani.net" X-Mailer: Perl5 Mail::Internet v2.05 X-Submission-Address: std-cpp-submit@vandevoorde.com Cancel-Lock: sha1:xsd7umsrq9NycToJBGCIES3kH2o= X-Original-Date: Wed, 19 Oct 2011 23:03:15 +0100 (BST) Xref: x330-a1.tempe.blueboxinc.net comp.std.c++:328 Hi, The C++11 IS allows literal types to have mutable members. In particular, programs like the following are legal: struct MM { mutable int n; }; template struct S { int k = n; }; int f(int k) { constexpr MM m = { 0 }; // ok, MM is a literal type m.n = k; // ok, m.n is mutable return S().k; // ok, an lvalue-to-rvalue conversion of // a subobject of a constexpr object is // a constant expression [expr.const]/2 } There seem to be two natural ways to fix this. Either (a) an lvalue-to-rvalue conversion on a mutable member of a constexpr object should be considered to not be a constant expression, or (b) literal types should not be allowed to have mutable members. (b) seems like the better solution, since it allows constexpr objects to be ROM-able, which the constexpr papers note as an explicit goal. The clang compiler currently implements (b). Thanks, Richard -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]