The following code give "error: initializer element is not constant" with gcc 3.4.0 in C99 mode on OSX 10.3.3. It compiled as expected with gcc 3.3 from Apple's X-Code 1.2. Section 7.12[5] of the C99 spec says that NAN expands to a constant expression. #include <math.h> const volatile static float arg2_float_23 = NAN; Similar results when I hard-coded the path to the 3.4.0 version of math.h; session below, and I'll attach the preprocessed file, which did indeed fail to define NAN as a constant. The problem seems to be that __APPLE_CC__ is no longer defined in 3.4.0 (though __APPLE__ still is); but the math.h with 3.4.0 (built from the gnu sources) still depends on it: #if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345) #define NAN __builtin_nanf("0x7fc00000") /* Constant expression, can be used as initializer. */ #else #define NAN __nan( ) #endif Adding "-D__APPLE_CC__=1642" to the command line worked around the problem. Here are the diffs between the predefined macros in the two versions; the other ones look fairly innocuous, except perhaps for __GXX_ABI_VERSION, which I don't understand. 3d2 < #define __APPLE_CC__ 1640 10a10,11 > #define __DBL_HAS_INFINITY__ 1 > #define __DBL_HAS_QUIET_NAN__ 1 24a26,27 > #define __FLT_HAS_INFINITY__ 1 > #define __FLT_HAS_QUIET_NAN__ 1 33c36 < #define __GNUC_MINOR__ 3 --- > #define __GNUC_MINOR__ 4 36c39 < #define __GXX_ABI_VERSION 102 --- > #define __GXX_ABI_VERSION 1002 40a44,45 > #define __LDBL_HAS_INFINITY__ 1 > #define __LDBL_HAS_QUIET_NAN__ 1 63c68 < #define __VERSION__ "3.3 20030304 (Apple Computer, Inc. build 1640)" --- > #define __VERSION__ "3.4.0" - - - /usr/local/gcc34/bin/gcc -std=c99 -pedantic -lmx -funsigned-char -v -save-temps -c ../c/noerror/ bugfiles/gcc_bugfiles/warn/NAN_not_const-full-path.c Reading specs from /usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/specs Configured with: configure --prefix=/usr/local/gcc34 Thread model: posix gcc version 3.4.0 /usr/local/gcc34/libexec/gcc/powerpc-apple-darwin7.3.0/3.4.0/cc1 -E -quiet -v -D__DYNAMIC__ ../ c/noerror/bugfiles/gcc_bugfiles/warn/NAN_not_const-full-path.c -fPIC -std=c99 -pedantic -funsigned-char -o NAN_not_const-full-path.i ignoring nonexistent directory "/usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/../../../../ powerpc-apple-darwin7.3.0/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/local/gcc34/include /usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/include /usr/include End of search list. /usr/local/gcc34/libexec/gcc/powerpc-apple-darwin7.3.0/3.4.0/cc1 -fpreprocessed NAN_not_const- full-path.i -fPIC -quiet -dumpbase NAN_not_const-full-path.c -auxbase NAN_not_const-full-path -pedantic -std=c99 -version -funsigned-char -o NAN_not_const-full-path.s GNU C version 3.4.0 (powerpc-apple-darwin7.3.0) compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495). GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 ../c/noerror/bugfiles/gcc_bugfiles/warn/NAN_not_const-full-path.c:2: error: initializer element is not constant
Created attachment 6375 [details] Pre-processed source, specifying full path to math.h
Confirmed, please report this to Apple also as this is a bug in Apple's headers, we can fixincludes them.
We can replace the check for __APPLE_CC__ with a check for __GNUC__, and __GNUC_MINOR__.
Apple bug #3666675: <https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa/6/wo/MPeQbCnDgtJADiIQLAsBN0/ 7.27>
I think I have a fixincl fix but I cannot test it until I build autogen which it fails for me. Here is the inclhack.def part which I created: /* * Fixup Darwin's broken check for __builtin_nanf. */ fix = { hackname = broken_nan; files = "architecture/ppc/math.h"; files = "architecture/i386/math.h"; select = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)" c_fix = format; c_fxi_arg = "#if defined(__GNUC__) && ((__GNUC__ > 4)||((__GNUC__ > 3) && (__GNUC_MINOR__ >= 3)))" test_text = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)" };
I should try this patch soon again now I can regenerate fixincludes.
I will take of this soon.
Hmm, this no longer works because we fixinclude architecture/ppc/math.h a different way now. I can no longer fix this.
This is also radar 4194286 now because I was tried of this not being fixed.
I have a fix which I am about to submit.
Subject: Bug 15642 Author: pinskia Date: Thu Jan 19 17:18:29 2006 New Revision: 109973 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109973 Log: 2006-01-19 Andrew Pinski <pinskia@physics.uc.edu> PR target/15642 * inclhack.def (AAB_darwin7_9_long_double_funcs [replace]): Define __APPLE_CC_ as 1345. (broken_nan): New. * fixincl.x: Regenerate. Modified: trunk/fixincludes/ChangeLog trunk/fixincludes/fixincl.x trunk/fixincludes/inclhack.def
Fixed in 4.2.0.