default setting of -fmath-errno


I was surprised by a difference between clang and gcc. On gcc, the
docs for -fno-math-errno say:

"This option is not turned on by any -O option since it can result in
incorrect output for programs which depend on an exact implementation
of IEEE or ISO rules/specifications for math functions."

But with clang, it seems that when I turn on any optimization (-O1 or
higher), I *do* get the effect of -fno-math-errno. Is this

There's a test case below. If I compile with "clang -O" and run it, I
get "result -nan, errno 0". I'm using the 3.0rc3 release on


#include <errno.h>
#include <math.h>
#include <stdio.h>

int main(int argc, const char *argv[])
  double d;
  errno = 0;
  d = sqrt(argc - 5);
  printf("result %g, errno %d\n", d, errno);
  return 0;

Yes, intentional; see We
should probably document it somewhere, though...


This seems like a poor decision since (as it says in the GCC docs
quoted above) -fno-math-errno can break valid programs. What's the
rationale? The bug report doesn't really explain much.