Closed
Description
Describe the bug
The following example works, however it is expected to fail.
I can
- re-move, already moved string.
- reassign moved string (unremark the //s = "test2";)
- cout already moved string
To Reproduce
Steps to reproduce the behavior:
- Sample code - distilled down to minimal essentials please
class Wraper {
public:
Wraper(const std::string &&p):s{std::move(p)}{
std::cout << "Moved !!!\n";
}
void foo(std::string &&x){
s=std::move(x);
}
void doPrint(){
std::cout << s;
}
std::string s;
};
main: () -> int = {
s:std::string ="Hello,!\n";
w:Wraper = move(s);
w.foo(move(s));
s="asd";
std::cout << "after move ** "<<s<<"**\n";
w.doPrint();
//s = "test2";
w.doPrint();
}
- Command lines including which C++ compiler you are using
clanf 14, macos
FetchContent_Declare(
cppfront
GIT_REPOSITORY https://github.com/modern-cmake/cppfront.git
GIT_TAG main # or an actual git SHA if you don't like to live dangerously
)
FetchContent_MakeAvailable(cppfront)
- Expected result - what you expected to happen
- error, can not move already moved var.
- |Error can not reassign moved var
- Error can not cout already moved var
- Actual result/error
- no error - that is the problem
Additional context
Add any other context about the problem here.
Compiled into
#line 23 "/Volumes/RAM_Disk_4G/g/main.cpp2"
[[nodiscard]] auto main() -> int{
std::string s {"Hello,!\n"};
Wraper w {move(s)};
CPP2_UFCS(foo, w, move(s));
s = "asd";
std::cout << "after move ** " << std::move(s) << "**\n";
CPP2_UFCS_0(doPrint, w);
//s = "test2";
CPP2_UFCS_0(doPrint, std::move(w));
}
clang, don't prevent this, so it is just unexpected behavior (s could be empty, or ref to old value)