Actually the segmentation fault happens in another program I tried to compile which happens because of this behaviour.
My question is:
This is a bug or my fault?
Reproducible in any way (even if the something
field is private or protected) and here is my example:
main.cc:
#include <iostream>
class Test {
public:
const char* something = "SOMETHING HERE!!!";
Test(const int& number) : Test(something, number) { }
// XXX: changed `something` to `_something` to make it different
Test(const char* _something, const int& number) {
std::cout << _something << std::endl;
std::cout << number << std::endl; }
~Test() { }
};
int main(int argc, char* argv[]) {
Test te1(345);
Test te2("asdasdad", 34523);
return 0;
}
And here is what happens when compiling with:
g++ main.cc -Os -o main
and running with:
./main
the output is:
pi@pi:~/ $ ./main
A"�~ <-- this is random
345
asdasdad
34523
But when I enable optimization with -O0
or -O1
or -O2
... the output is only a new line:
pi@pi:~/ $ ./main
pi@pi:~/ $
G++ version:
pi@pi:~/ $ g++ --version
g++ (Raspbian 6.3.0-18+rpi1) 6.3.0 20170516