summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema
diff options
context:
space:
mode:
authorMatthias Gehre <M.Gehre@gmx.de>2019-08-14 21:55:57 +0000
committerMatthias Gehre <M.Gehre@gmx.de>2019-08-14 21:55:57 +0000
commit1bebc22bd94d44214bbd8a2dad10736c7c5e205b (patch)
treecd8efa570ec89f3a5680df4fd20bcc92b2586e09 /clang/test/Sema
parent4395b31d99577a0e753403426bca761482a58a52 (diff)
downloadbcm5719-llvm-1bebc22bd94d44214bbd8a2dad10736c7c5e205b.tar.gz
bcm5719-llvm-1bebc22bd94d44214bbd8a2dad10736c7c5e205b.zip
[LifetimeAnalysis] Support std::stack::top() and std::optional::value()
Summary: Diagnose dangling pointers that come from std::stack::top() and std::optional::value(). Reviewers: gribozavr Subscribers: cfe-commits, xazax.hun Tags: #clang Differential Revision: https://reviews.llvm.org/D66164 llvm-svn: 368929
Diffstat (limited to 'clang/test/Sema')
-rw-r--r--clang/test/Sema/warn-lifetime-analysis-nocfg.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
index ba3cc1fc969..c8016bf55cb 100644
--- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
@@ -170,7 +170,15 @@ template<typename T>
struct optional {
optional();
optional(const T&);
- T &operator*();
+ T &operator*() &;
+ T &&operator*() &&;
+ T &value() &;
+ T &&value() &&;
+};
+
+template<typename T>
+struct stack {
+ T &top();
};
}
@@ -188,6 +196,16 @@ const char *danglingRawPtrFromLocal() {
return s.c_str(); // expected-warning {{address of stack memory associated with local variable 's' returned}}
}
+int &danglingRawPtrFromLocal2() {
+ std::optional<int> o;
+ return o.value(); // expected-warning {{reference to stack memory associated with local variable 'o' returned}}
+}
+
+int &danglingRawPtrFromLocal3() {
+ std::optional<int> o;
+ return *o; // expected-warning {{reference to stack memory associated with local variable 'o' returned}}
+}
+
const char *danglingRawPtrFromTemp() {
return std::basic_string<char>().c_str(); // expected-warning {{returning address of local temporary object}}
}
@@ -203,9 +221,10 @@ int *danglingUniquePtrFromTemp2() {
}
void danglingReferenceFromTempOwner() {
- int &r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
- int &r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
- int &r3 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
+ int &&r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
+ int &&r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
+ int &&r3 = std::optional<int>(5).value(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
+ int &r4 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
}
std::vector<int> getTempVec();
OpenPOWER on IntegriCloud