@@ -634,18 +634,27 @@ void test() {
634
634
std::optional<std::string_view> o3 = std::optional<std::string>(s); // expected-warning {{object backing the pointer}}
635
635
std::optional<std::string_view> o4 = std::optional<std::string_view>(s);
636
636
637
- // FIXME: should work for assignment cases
638
- v1 = {std::string ()};
639
- o1 = std::string ();
637
+ v1 = {std::string ()}; // expected-warning {{object backing the pointer}}
638
+ o1 = std::string (); // expected-warning {{object backing the pointer}}
640
639
641
640
// no warning on copying pointers.
642
641
std::vector<std::string_view> n1 = {std::string_view ()};
642
+ n1 = {std::string_view ()};
643
643
std::optional<std::string_view> n2 = {std::string_view ()};
644
+ n2 = {std::string_view ()};
644
645
std::optional<std::string_view> n3 = std::string_view ();
646
+ n3 = std::string_view ();
645
647
std::optional<std::string_view> n4 = std::make_optional (std::string_view ());
648
+ n4 = std::make_optional (std::string_view ());
646
649
const char * b = " " ;
647
650
std::optional<std::string_view> n5 = std::make_optional (b);
651
+ n5 = std::make_optional (b);
648
652
std::optional<std::string_view> n6 = std::make_optional (" test" );
653
+ n6 = std::make_optional (" test" );
654
+ // Deeper nested containers are not supported; only first-level nesting is
655
+ // supported.
656
+ std::vector<std::vector<std::string_view>> n7 = {{std::string ()}};
657
+ n7 = {{std::string ()}};
649
658
}
650
659
651
660
std::vector<std::string_view> test2 (int i) {
@@ -683,7 +692,9 @@ std::optional<std::string_view> test3(int i) {
683
692
return s; // expected-warning {{address of stack memory associated}}
684
693
return sv; // fine
685
694
Container2<std::string_view> c1 = Container1<Foo>(); // no diagnostic as Foo is not an Owner.
695
+ c1 = Container1<Foo>();
686
696
Container2<std::string_view> c2 = Container1<FooOwner>(); // expected-warning {{object backing the pointer will be destroyed}}
697
+ c2 = Container1<FooOwner>(); // expected-warning {{object backing the pointer}}
687
698
return GetFoo (); // fine, we don't know Foo is owner or not, be conservative.
688
699
return GetFooOwner (); // expected-warning {{returning address of local temporary object}}
689
700
}
@@ -713,10 +724,12 @@ struct [[gsl::Pointer]] Span {
713
724
// Pointer from Owner<Pointer>
714
725
std::string_view test5 () {
715
726
std::string_view a = StatusOr<std::string_view>().valueLB (); // expected-warning {{object backing the pointer will be dest}}
727
+ a = StatusOr<std::string_view>().valueLB (); // expected-warning {{object backing the pointer}}
716
728
return StatusOr<std::string_view>().valueLB (); // expected-warning {{returning address of local temporary}}
717
729
718
730
// No dangling diagnostics on non-lifetimebound methods.
719
731
std::string_view b = StatusOr<std::string_view>().valueNoLB ();
732
+ b = StatusOr<std::string_view>().valueNoLB ();
720
733
return StatusOr<std::string_view>().valueNoLB ();
721
734
}
722
735
@@ -773,8 +786,10 @@ const int& test12(Span<int> a) {
773
786
void test13 () {
774
787
// FIXME: RHS is Owner<Pointer>, we skip this case to avoid false positives.
775
788
std::optional<Span<int *>> abc = std::vector<int *>{};
789
+ abc = std::vector<int *> {};
776
790
777
791
std::optional<Span<int >> t = std::vector<int > {}; // expected-warning {{object backing the pointer will be destroyed}}
792
+ t = std::vector<int > {}; // expected-warning {{object backing the pointer}}
778
793
}
779
794
780
795
} // namespace GH100526
0 commit comments