------- Additional Comments From ian at airs dot com 2005-02-13 20:27 ------- The definition of pure states that such a function may depend upon global variables. I guess you are saying that func_pure_2 is not pure because the global variable a may not be a valid memory address?
I disagree. If the programmer declares that func_pure_2 is pure, then the programmer is promising the compiler that the variable a holds a valid memory address. The attribute is not a statement of something which the compiler can deduce for itself; it is a promise by the programmer. Given that promise, the compiler is fully entitled and expected to hoist function calls out of loops which do not modify global variables, etc. If that causes a bug, it is a bug in the code, not in the compiler. I agree that it would be nice if the compiler could do a better job of analyzing whether a function is const/pure, but until then we should trust the programmer. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19828