Opened 7 years ago
Closed 4 years ago
#9135 closed enhancement (fixed)
"Access of moved variable" not detected in loop
| Reported by: | kidkat | Owned by: | pfultz2 |
|---|---|---|---|
| Priority: | Normal | Milestone: | 2.9 |
| Component: | Improve check | Version: | |
| Keywords: | c++11 accessMoved valueflow | Cc: |
Description (last modified by )
#include <string> static void func2(std::string&& s) { (void)s; } static void func() { std::string p; while(true) { func2(std::move(p)); } }
Change History (7)
comment:1 by , 6 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 5 years ago
| Keywords: | valueflow added |
|---|
No warning for this either:
void g(std::string&& s);
void f() {
std::string p;
for (int i = 0; i < 2; ++i)
g(std::move(p));
}
comment:4 by , 4 years ago
| Description: | modified (diff) |
|---|
comment:5 by , 4 years ago
| Milestone: | → 2.9 |
|---|---|
| Owner: | changed from to |
| Status: | new → accepted |
comment:7 by , 4 years ago
| Resolution: | → fixed |
|---|---|
| Status: | accepted → closed |
Note:
See TracTickets
for help on using tickets.
A variation based on the bug fixed in https://github.com/danmar/cppcheck/commit/96704c997143dfd126db9c61d2e9cc129fabe2f1
##file /mnt/s/clion/example_lite_2/test.cpp 3: extern std :: list < int > func ( std :: list < int > && ) ; 4: 5: static void f ( std :: list < int > l@var1 ) 6: { 7: for (@expr4 int i@var2 = 0 ; i@var2 <@expr5 10 ; ++ i@var2 ) { 8: for (@expr6 auto &@expr7 j@var3 : func (@expr8 std :: move (@expr9 l@var1 ) ) ) { } 9: } 10: } ##Value flow Line 7 0 always 0 10 always 10 Line 8 ( possible lifetime=l