[PATCH] D66164: [LifetimeAnalysis] Support std::stack::top() and std::optional::value()
Matthias Gehre via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 13 15:35:35 PDT 2019
mgehre updated this revision to Diff 214950.
mgehre marked 2 inline comments as done.
mgehre added a comment.
Fix commit
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66164/new/
https://reviews.llvm.org/D66164
Files:
clang/lib/Sema/SemaInit.cpp
clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
Index: clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
===================================================================
--- clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+++ clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
@@ -168,7 +168,14 @@
struct optional {
optional();
optional(const T&);
- T &operator*();
+ T &operator*() &;
+ T &&operator*() &&;
+ T &value() &;
+};
+
+template<typename T>
+struct stack {
+ T &top();
};
}
@@ -186,6 +193,16 @@
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}}
}
@@ -201,9 +218,8 @@
}
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 &r1 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
+ int &r2 = std::stack<int>().top(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
}
std::vector<int> getTempVec();
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6591,7 +6591,7 @@
OO == OverloadedOperatorKind::OO_Star;
}
return llvm::StringSwitch<bool>(Callee->getName())
- .Cases("front", "back", "at", true)
+ .Cases("front", "back", "at", "top", "value", true)
.Default(false);
}
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66164.214950.patch
Type: text/x-patch
Size: 2368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190813/a5bd9120/attachment.bin>
More information about the cfe-commits
mailing list