I've got the following issue where the output in debug appears to completely defy what the code says and it seems like it could be a bug in the compiler unless I'm missing something.
So here's the code, it's supposed to create two filename strings and delete one of the files.
auto *real = (base_dir + "/index.txt").c_str();
auto *bkp = (base_dir + "/index.txt.new").c_str();
remove(real);
However, it does not exhibit this behavior in practice, and in reality we get the following in gdb:
auto *real = (base_dir + "/index.txt").c_str();
(gdb) n
auto *bkp = (base_dir + "/index.txt.new").c_str();
(gdb) n
remove(real);
(gdb) p real
$1 = 0x7060e8 "./ss-clientdir/index.txt.new"
(gdb) p bkp
$2 = 0x7060e8 "./ss-clientdir/index.txt.new"
So as you can see, despite the strings being initialized using two different expressions with different string literals, after initialization they end up as the same pointer to the same string.
Is this some compiler optimization gone off the rails or what?
Aucun commentaire:
Enregistrer un commentaire