Newer gcc swallow version control keywords

Newer gcc swallow version control keywords

Nadav Har'El nyh at math.technion.ac.il
Tue Oct 18 16:04:48 IST 2011


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?

But unfortunately, whether this is to be called a "bug" doesn't really
help you :(

-- 
Nadav Har'El                        |                   Tuesday, Oct 18 2011, 
nyh at math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |This '|' is not a pipe.
http://nadav.harel.org.il           |



More information about the Linux-il mailing list