On Tue, Oct 18, 2011 at 4:04 PM, Nadav Har'El <n...@math.technion.ac.il> wrote: > On Tue, Oct 18, 2011, Oleg Goldshmidt wrote about "Re: Newer gcc swallow > version control keywords": >> It was about C++. C and C++ compilers behave the same. > > I was very surprised to discover that this is indeed the case. I think this > is a BUG. For example, consider this C++ program: > > #include <cstdio> > class Ident { > public: > Ident(const char *ident){ > // This constructor prints a message! > printf("yo\n"); > } > }; > > static Ident id("$Id: hello $"); > > main(){ > printf("hello\n"); > } > > > If you compile it with g++ (without optimization), the object id gets > instanciated, and when you run the program you see the message "yo" first, > before "hello". But, if you compile it with g++ -O2, id gets optimized out > and its constructor never runs - and you never see the "yo" message. > > So basically, compiling with -O2 changes the *behavior*, not just the > *performance*, of the code. I don't know how this cannot be called a bug?
Actually, it works fine for me with or without -O2, with g++ 4.6.1 on F15. What am I doing wrong? ;-) -- Oleg Goldshmidt | p...@goldshmidt.org _______________________________________________ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il