Funny clang behaviour

Vincent Lefevre vincent at
Tue Feb 18 14:51:48 UTC 2020

On 2020-02-18 12:47:31 +0100, Niels Möller wrote:
> Marc Glisse <marc.glisse at> writes:
> > but in any case it seems like a good idea to avoid having a
> > file with the same name as a standard header in a directory with a -I
> > pointing to it.
> I wonder why we have an -I flag pointing to tests/mpz. We don't have any
> header files there.

IMHO, the use of -I pointing to any directory that contains files
other than headers that are meant to be installed in "public"
include directories is incorrect. Even if this currently yields
no issues, this might break at any time, as seen here with <bit>.

Note that clang is not the only potential cause of failures.
For instance, under Linux, /usr/include/stdio.h contains

#include <bits/types.h>

so that if you have a source tree with a subdirectory "bits" that
contains a file "types.h", then this may break.

But that's a design bug of Automake. What it should have done
is to create an include directory and copy (or symlink) into it
header files to be installed (e.g. gmp.h), and use -I with this
include directory. For the other files, included with quotes
(e.g. gmp-impl.h), it seems that for GCC, the right option is
-iquote (but unfortunately that's specific to GCC, and there's
no standard to avoid a clash with headers).

> Is a generic "-I." added somewhere ? Looking in
>, I see
>   $ grep -- -I tests/mpz/ 
>   DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
>   AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/tests
> The -I$(top...)... things should be no problem. So I'd guess it's the
>   -I. at am__isrc@
> What's @am__isrc@?

In aclocal.m4:

AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl

So the issue *here* seems to be with "-I.", not necessarily with
@am__isrc@ (but see above about the wrong use of -I in general).

> Is there a way to tell automake to omit it in DEFAULT_INCLUDES?


8.7 Variables used when building a program

     Automake already provides some ‘-I’ options automatically, in a
     separate variable that is also passed to every compilation that
     invokes the C preprocessor.  In particular it generates ‘-I.’,
     ‘-I$(srcdir)’, and a ‘-I’ pointing to the directory holding
     ‘config.h’ (if you’ve used ‘AC_CONFIG_HEADERS’).  You can disable
     the default ‘-I’ options using the ‘nostdinc’ option.

Vincent Lefèvre <vincent at> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the gmp-devel mailing list