You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Don't emit bogus dangling diagnostics when [[gsl::Owner]] and [[clang::lifetimebound]] are used together. (#108280)
In the GSL analysis, we don't track the `this` object if the conversion
is not from gsl::owner to gsl pointer, we want to be conservative here
to avoid triggering false positives.
Fixes#108272
Copy file name to clipboardExpand all lines: clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+34Lines changed: 34 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -553,3 +553,37 @@ void test() {
553
553
std::string_view svjkk1 = ReturnStringView(StrCat("bar", "x")); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
554
554
}
555
555
} // namespace GH100549
556
+
557
+
namespaceGH108272 {
558
+
template <typename T>
559
+
struct [[gsl::Owner]] StatusOr {
560
+
const T &value() [[clang::lifetimebound]];
561
+
};
562
+
563
+
template <typename V>
564
+
classWrapper1 {
565
+
public:
566
+
operatorV() const;
567
+
V value;
568
+
};
569
+
std::string_view test1() {
570
+
StatusOr<Wrapper1<std::string_view>> k;
571
+
// Be conservative in this case, as there is not enough information available
572
+
// to infer the lifetime relationship for the Wrapper1 type.
573
+
std::string_view good = StatusOr<Wrapper1<std::string_view>>().value();
574
+
return k.value();
575
+
}
576
+
577
+
template <typename V>
578
+
classWrapper2 {
579
+
public:
580
+
operatorV() const [[clang::lifetimebound]];
581
+
V value;
582
+
};
583
+
std::string_view test2() {
584
+
StatusOr<Wrapper2<std::string_view>> k;
585
+
// We expect dangling issues as the conversion operator is lifetimebound。
586
+
std::string_view bad = StatusOr<Wrapper2<std::string_view>>().value(); // expected-warning {{temporary whose address is used as value of}}
587
+
return k.value(); // expected-warning {{address of stack memory associated}}
0 commit comments