diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-07-24 07:11:57 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-07-24 07:11:57 +0000 |
| commit | 08d6a2cc7a58cfc0d04ed7215ab0b7b9d3193494 (patch) | |
| tree | aba9062cfe5847e670b2ebc63058a173c480178e /clang/test/SemaCXX/constant-expression-cxx11.cpp | |
| parent | 6bcb34b180f7e7a89d72cdfd8dcf9e2acdb3d262 (diff) | |
| download | bcm5719-llvm-08d6a2cc7a58cfc0d04ed7215ab0b7b9d3193494.tar.gz bcm5719-llvm-08d6a2cc7a58cfc0d04ed7215ab0b7b9d3193494.zip | |
C++1y: track object lifetime during constexpr evaluation, and don't allow
objects to be used once their lifetimes end. This completes the C++1y
constexpr extensions.
llvm-svn: 187025
Diffstat (limited to 'clang/test/SemaCXX/constant-expression-cxx11.cpp')
| -rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx11.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index dc8b6346fe7..8d16962387e 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1709,3 +1709,21 @@ namespace ConstexprConstructorRecovery { }; constexpr X x{}; } + +namespace Lifetime { + void f() { + constexpr int &n = n; // expected-error {{constant expression}} expected-note {{use of reference outside its lifetime}} expected-warning {{not yet bound to a value}} + constexpr int m = m; // expected-error {{constant expression}} expected-note {{read of object outside its lifetime}} + } + + constexpr int &get(int &&n) { return n; } + struct S { + int &&r; // expected-note 2{{declared here}} + int &s; + int t; + constexpr S() : r(0), s(get(0)), t(r) {} // expected-warning {{temporary}} + constexpr S(int) : r(0), s(get(0)), t(s) {} // expected-warning {{temporary}} expected-note {{read of object outside its lifetime}} + }; + constexpr int k1 = S().t; // ok, int is lifetime-extended to end of constructor + constexpr int k2 = S(0).t; // expected-error {{constant expression}} expected-note {{in call}} +} |

