#include <string> void printA(std::string str); void printB(std::string str); int main(int argc, char **argv) { std::string str = "test it"; argc>1?printA(std::move(str)):printB(std::move(str)); }
In the ternary if only one of the two moves will take place.
.\cppcheck\bin\cppcheck.exe .\test.cpp --enable=warning Checking test.cpp ... test.cpp:8:50: warning: Access of moved variable 'str'. [accessMoved] argc>1?printA(std::move(str)):printB(std::move(str)); ^ test.cpp:8:17: note: Calling std::move(str) argc>1?printA(std::move(str)):printB(std::move(str)); ^ test.cpp:8:50: note: Access of moved variable 'str'. argc>1?printA(std::move(str)):printB(std::move(str));
https://trac.cppcheck.net/ticket/12174
Log in to post a comment.
In the ternary if only one of the two moves will take place.
Last edit: Stefan van Kessel 2023-11-11
https://trac.cppcheck.net/ticket/12174