diff options
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()}; + } +} |