diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-07-23 21:21:24 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-07-23 21:21:24 +0000 |
commit | 6a32c0589cd2b60bf599b8aede33c484ec359e7a (patch) | |
tree | 80a6de6092b8e4650e5cdb28444b5a8ea44b0c28 /clang/test/SemaCXX/conditional-expr.cpp | |
parent | afe48f9d68e446829bed6ce72b319c915873809a (diff) | |
download | bcm5719-llvm-6a32c0589cd2b60bf599b8aede33c484ec359e7a.tar.gz bcm5719-llvm-6a32c0589cd2b60bf599b8aede33c484ec359e7a.zip |
Do not try to perform lifetime-extension through conditional
expressions.
CodeGen can't cope with that yet. Instead, produce a "not supported"
warning for now and don't extend lifetime.
llvm-svn: 337744
Diffstat (limited to 'clang/test/SemaCXX/conditional-expr.cpp')
-rw-r--r-- | clang/test/SemaCXX/conditional-expr.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp index 7e6b0ce8e8f..ab19ce54b69 100644 --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -Wsign-conversion %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++17 -Wsign-conversion %s // C++ rules for ?: are a lot stricter than C rules, and have to take into // account more conversion options. @@ -228,7 +229,7 @@ void test() // be properly tested at runtime, though. const Abstract &abstract1 = true ? static_cast<const Abstract&>(Derived1()) : Derived2(); // expected-error {{allocating an object of abstract class type 'const Abstract'}} - const Abstract &abstract2 = true ? static_cast<const Abstract&>(Derived1()) : throw 3; // ok + const Abstract &abstract2 = true ? static_cast<const Abstract&>(Derived1()) : throw 3; // expected-warning-re {{sorry, lifetime extension {{.*}} not supported}} } namespace PR6595 { @@ -393,3 +394,22 @@ Derived d; typedef decltype(true ? static_cast<Base&&>(b) : static_cast<Derived&&>(d)) x; typedef Base &&x; } + +namespace lifetime_extension { + struct A {}; + struct B : A { B(); ~B(); }; + struct C : A { C(); ~C(); }; + + void f(bool b) { + // expected-warning@+1 2{{sorry, lifetime extension of temporary created within conditional expression is not supported}} + A &&r = b ? static_cast<A&&>(B()) : static_cast<A&&>(C()); + } + + struct D { A &&a; }; + void f_indirect(bool b) { +#if __cplusplus >= 201702L + // expected-warning@+2 2{{sorry, lifetime extension of temporary created within conditional expression is not supported}} +#endif + D d = b ? D{B()} : D{C()}; + } +} |