I have a doubt on basic C++ usage. The code below, compiled with gcc/LInux, prints out correctly.
The string test goes out of scope so also its c_
test
c_
Because test goes out of scope, what you are doing is undefined behavior. Do not make assumptions about how it will function.
It could just as well segfault and the behavior will still be correct. UB is UB.