@@ -440,6 +440,7 @@ void no_error_loan_from_current_iteration(bool cond) {
440440// ===----------------------------------------------------------------------===//
441441
442442View Identity (View v [[clang::lifetimebound]]);
443+ MyObj* Identity (MyObj* v [[clang::lifetimebound]]);
443444View Choose (bool cond, View a [[clang::lifetimebound]], View b [[clang::lifetimebound]]);
444445MyObj* GetPointer (const MyObj& obj [[clang::lifetimebound]]);
445446
@@ -582,3 +583,55 @@ void lifetimebound_ctor() {
582583 }
583584 (void )v;
584585}
586+
587+ // Conditional operator.
588+ void conditional_operator (bool cond) {
589+ MyObj safe;
590+ MyObj* p = &safe;
591+ {
592+ MyObj temp;
593+ p = cond ? &temp // expected-warning {{object whose reference is captured may not live long enough}}
594+ : &safe;
595+ } // expected-note {{destroyed here}}
596+ if (cond) p = &safe;
597+ (void )*p; // expected-note {{later used here}}
598+
599+ {
600+ MyObj a, b;
601+ p = cond ? &a // expected-warning {{object whose reference is captured does not live long enough}}
602+ : &b; // expected-warning {{object whose reference is captured does not live long enough}}
603+ } // expected-note 2 {{destroyed here}}
604+ (void )*p; // expected-note 2 {{later used here}}
605+
606+ {
607+ MyObj a, b, c, d;
608+ p = cond ? cond ? &a // expected-warning {{object whose reference is captured does not live long enough}}.
609+ : &b // expected-warning {{object whose reference is captured does not live long enough}}.
610+ : cond ? &c // expected-warning {{object whose reference is captured does not live long enough}}.
611+ : &d; // expected-warning {{object whose reference is captured does not live long enough}}.
612+ } // expected-note 4 {{destroyed here}}
613+ (void )*p; // expected-note 4 {{later used here}}
614+
615+ {
616+ MyObj a, b;
617+ p = Identity (cond ? &a // expected-warning {{object whose reference is captured does not live long enough}}
618+ : &b); // expected-warning {{object whose reference is captured does not live long enough}}
619+ } // expected-note 2 {{destroyed here}}
620+ (void )*p; // expected-note 2 {{later used here}}
621+
622+ {
623+ MyObj a, b;
624+ p = Identity (cond ? Identity (&a) // expected-warning {{object whose reference is captured does not live long enough}}
625+ : Identity (&b)); // expected-warning {{object whose reference is captured does not live long enough}}
626+ } // expected-note 2 {{destroyed here}}
627+ (void )*p; // expected-note 2 {{later used here}}
628+
629+ {
630+ MyObj a, b, c, d;
631+ p = Identity (cond ? Identity (cond ? &a // expected-warning {{object whose reference is captured does not live long enough}}
632+ : &b) // expected-warning {{object whose reference is captured does not live long enough}}
633+ : Identity (cond ? &c // expected-warning {{object whose reference is captured does not live long enough}}
634+ : &d)); // expected-warning {{object whose reference is captured does not live long enough}}
635+ } // expected-note 4 {{destroyed here}}
636+ (void )*p; // expected-note 4 {{later used here}}
637+ }
0 commit comments