From: Richard Smith Date: Fri, 23 Feb 2018 02:03:26 +0000 (+0000) Subject: Add a test to ensure we don't permit mutable access on temporaries outside the evalua... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=747af81d641228a3221f923c103818e0ea2cf38c;p=clang Add a test to ensure we don't permit mutable access on temporaries outside the evaluation in which they were created. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325854 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/SemaCXX/constant-expression-cxx1y.cpp b/test/SemaCXX/constant-expression-cxx1y.cpp index f81988c4db..d22cba430a 100644 --- a/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/test/SemaCXX/constant-expression-cxx1y.cpp @@ -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(const_cast(a)) }; // expected-error {{constant expression}} expected-note@-7 {{mutable}} + constexpr Q r = { static_cast(const_cast(a)) }; // expected-error {{constant expression}} expected-note@-8 {{mutable}} struct B { mutable int n; // expected-note {{here}}