================
@@ -1015,3 +1015,22 @@ struct OtherMoveSafeClasses {
// aggressive-note@-2 {{Moved-from object 'Task' is moved}}
}
};
+
+void safeOperatorAfterMove() {
+ std::list<std::string> l1;
+ l1.push_back("l1");
+ std::list<std::string> l2;
----------------
steakhal wrote:
Couldn't we rewrite these test cases to have a bit less ceremony?
```
template <class Container>
void safeOperatorAfterMove(Container src) {
Container dst;
std::move(src.begin(), src.end(), std::back_inserter(dst));
auto val = *dst.begin(); // no-warning: 'dst' just got populated, it's
(probably) fine to access assuming it had at least one element
(void)val;
}
int InstantiateSafeOperatorAfterMoveTests() {
safeOperatorAfterMove(std::list<int>());
safeOperatorAfterMove(std::vector<int>());
safeOperatorAfterMove(std::map<int>());
safeOperatorAfterMove(std::list<std::string>());
safeOperatorAfterMove(std::vector<std::string>());
safeOperatorAfterMove(std::map<std::string>());
}
template <class Container>
void unsafeOperatorAfterMove(Container src) {
Container dst;
std::move(src.begin(), src.end(), std::back_inserter(dst));
// Pretend we had a typo, and we accidentally use the now moved 'src'.
auto val = *src.begin(); // expected-warning 6 {{stuff}}
(void)val;
}
int InstantiateUnsafeOperatorAfterMoveTests() {
unsafeOperatorAfterMove(std::list<int>());
unsafeOperatorAfterMove(std::vector<int>());
unsafeOperatorAfterMove(std::map<int>());
unsafeOperatorAfterMove(std::list<std::string>());
unsafeOperatorAfterMove(std::vector<std::string>());
unsafeOperatorAfterMove(std::map<std::string>());
}
```
https://github.com/llvm/llvm-project/pull/196602
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits