Hi,

compiling bison 3.0.3 with gcc-4.0.1 (Apple Inc. build 5493) (latest
available on Mac OS X 10.5) fails with the following error:

  CC       lib/math.o
In file included from lib/math.h:27,
                 from lib/math.h:27,
[about a 100 repeats]
                 from lib/math.c:3:
lib/math.h:27:23: error: #include nested too deeply
make[2]: *** [lib/math.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

The cause is usage of #include_next in conjunction with #include
"math.h" (as opposed to #include <math.h>) and adding the lib
subdirectory to the search path via -Ilib. If either -Ilib is changed to
-I./lib or #include "math.h" to #include <math.h> the problem does away.
So this certainly seems to be some sort of bug in gcc.

I've created a small test case which reports the following with Apple's
gcc-4.0.1:

michael@osx105box$ ./test.sh 
compile command: gcc -c -o /dev/null -I./lib lib/math.c
math.c compiled fine with working cpp flags
compile command: gcc -c -o /dev/null -Ilib lib/math.c
In file included from lib/math.h:2,
                 from lib/math.h:2,
[about a 100 repeats]
                 from lib/math.h:2,
                 from lib/math.c:1:
lib/math.h:2:23: error: #include nested too deeply
math.c did not compile with broken cpp flags
compile command: gcc -c -o /dev/null -I./lib lib/math_path.c
math_path.c compiled fine with working cpp flags
compile command: gcc -c -o /dev/null -Ilib lib/math_path.c
math_path.c compiled fine with broken cpp flags

This seems to have been fixed in later versions of (Apple) gcc and also
doesn't happen with various versions of clang I've tried. Though clang
complains "./lib/math.h:2:2: warning: #include_next with absolute path"
when using #include "math.h" if the header does not contain "#pragma GCC
system_header".

So I'd like to suggest changing -Ilib to -I./lib as in the attached
patch to avoid this problem with older gccs.
-- 
Thanks,
Michael
--- bison-3.0.3/Makefile.am.orig	2015-01-16 17:43:51.000000000 +0100
+++ bison-3.0.3/Makefile.am	2015-01-16 17:43:42.000000000 +0100
@@ -40,7 +40,7 @@
 # Initialization before completion by local.mk's.
 AM_CFLAGS = $(WARN_CFLAGS)
 # Find builddir/src/scan-code.c etc.
-AM_CPPFLAGS = -I. -Ilib -I$(top_srcdir) -I$(top_srcdir)/lib
+AM_CPPFLAGS = -I. -I./lib -I$(top_srcdir) -I$(top_srcdir)/lib
 BUILT_SOURCES =
 CLEANFILES =
 DISTCLEANFILES =

Attachment: testcase.tar.gz
Description: Binary data

Reply via email to