r325854 - Add a test to ensure we don't permit mutable access on temporaries outside the evaluation in which they were created.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 22 18:03:26 PST 2018
Author: rsmith
Date: Thu Feb 22 18:03:26 2018
New Revision: 325854
URL: http://llvm.org/viewvc/llvm-project?rev=325854&view=rev
Log:
Add a test to ensure we don't permit mutable access on temporaries outside the evaluation in which they were created.
Modified:
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=325854&r1=325853&r2=325854&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Thu Feb 22 18:03:26 2018
@@ -1028,13 +1028,14 @@ namespace Mutable {
static_assert(k == 123, "");
struct Q { A &&a; int b = a.n; };
- constexpr Q q = { A{456} }; // ok
+ constexpr Q q = { A{456} }; // expected-note {{temporary}}
static_assert(q.b == 456, "");
+ static_assert(q.a.n == 456, ""); // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}}
constexpr A a = {123};
constexpr int m = a.n; // expected-error {{constant expression}} expected-note {{mutable}}
- constexpr Q r = { static_cast<A&&>(const_cast<A&>(a)) }; // expected-error {{constant expression}} expected-note at -7 {{mutable}}
+ constexpr Q r = { static_cast<A&&>(const_cast<A&>(a)) }; // expected-error {{constant expression}} expected-note at -8 {{mutable}}
struct B {
mutable int n; // expected-note {{here}}
More information about the cfe-commits
mailing list