So we have run into a failing test on Linux which I suppose stems from wrong assumptions on my side regarding the validity of pointers referring to built-in literals. The code looks similar to this pseudo code:
auto obj = func( 'c', "str" ); // (1)
big_type big_object; // (2)
At (1), func() returns an object that stores a const pointer to the character literal and one to the string literal. Inspection in the debugger shows that both are correct.
At (2), debugging shows that what used to be a 'c' at the memory referenced to by the const char* in obj is overwritten.
Tets show that this also happens with int and double literals. This happens on GCC 5.4.1, it does not happen on GCC 4.1.2.
Having done C++ for >25 years, I have learned to suppose that, usually, the compiler is right and I am wrong; so I am doing this here, too.
However, while I know that, if this only regards literals of small built-in types, I can fix this (by copying them instead of referring to them), if this could happen with arbitrarily-sized objects ("str") as well, we have a pretty big problem.
So can someone please explain the exact rules regarding this?