[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#503204: gcc-4.1: erroneously emits warning on C99-required #pragma STDC FENV_ACCESS



Hi,
Bastian Blank wrote:

It's obviously buggy to emit a warning on standards-mandated behaviour! I know you can turn this warning off with -Wno-unknown-pragmas, but that's not something you want to be doing in production code.

Please show the part of the standard. A compiler may produce warnings
without reason.

Was the section I quoted in my original bug report not sufficient? Paragraph 7.6.1.2 of C99 says [again]:

"If part of a program tests floating-point status flags, sets floating-point control modes, or runs under non-default mode settings, but was translated with the state for the FENV_ACCESS pragma "off", *the behaviour is undefined*." [emphasis mine]

These are things that many correct programs will want to do. For example, SuSv3 has this to say about pow():

"An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred."[1]

Gcc as-is, will encourage (quite strongly, since may people will compile with -Wall, +/- -Werror) users to write code that calls feclearexcept() and suchlike without using #pragma STDC FENV_ACCESS ON first. This is undefined behaviour, according to C99! It seems clear to me that this is a bug in gcc.

Regards,

Matthew

[1] http://www.opengroup.org/onlinepubs/009695399/functions/pow.html



Reply to: