Bug 65227 - Plugin headers are unusable when included after inttypes.h
Summary: Plugin headers are unusable when included after inttypes.h
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: plugins (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: documentation
Depends on:
Blocks:
 
Reported: 2015-02-26 19:30 UTC by Bert Wesarg
Modified: 2015-02-27 08:56 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-02-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bert Wesarg 2015-02-26 19:30:05 UTC
GCC 5 20150215 Snapshot.

When the gcc-plugin.h header is included after the inttypes.h header, than the compilation breaks. Used compiler:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/wesarg/opt/gcc-5-20150215/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/home/wesarg/opt/gcc-5-20150215 --enable-languages=c,c++,fortran --disable-nls --enable-checking=yes --disable-werror
Thread model: posix
gcc version 5.0.0 20150215 (experimental) (GCC) 

Compiling the attached file, which includes inttypes.h before gcc-plugin.h results in this error:

$ g++ -save-temps -c -I$(g++ -print-file-name=plugin/include) no-inttypes-pri-macros.cc 
In file included from /home/wesarg/opt/gcc-5-20150215/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/plugin/include/double-int.h:23:0,
                 from /home/wesarg/opt/gcc-5-20150215/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/plugin/include/gcc-plugin.h:52,
                 from no-inttypes-pri-macros.cc:2:
/home/wesarg/opt/gcc-5-20150215/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/plugin/include/wide-int.h: In member function 'void generic_wide_int<T>::dump() const':
/home/wesarg/opt/gcc-5-20150215/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/plugin/include/wide-int.h:877:26: error: expected ')' before 'PRIx64'
     fprintf (stderr, HOST_WIDE_INT_PRINT_HEX ",", val[len - 1 - i]);
                          ^
In file included from /home/wesarg/opt/gcc-5-20150215/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/plugin/include/double-int.h:23:0,
                 from /home/wesarg/opt/gcc-5-20150215/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/plugin/include/gcc-plugin.h:52,
                 from no-inttypes-pri-macros.cc:2:
/home/wesarg/opt/gcc-5-20150215/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/plugin/include/wide-int.h:878:24: error: expected ')' before 'PRIx64'
   fprintf (stderr, HOST_WIDE_INT_PRINT_HEX "], precision = %d\n",
                        ^
The reason seems to be, that system.h defines __STDC_FORMAT_MACROS, than conditionally includes inttypes.h, and later hwint.h relys that this conditional include has resulted in the definition of the PRI macros. But that is not the case as the the include <inttypes.h> in system.h is not the first inclusion of this header.
Comment 1 Andrew Pinski 2015-02-26 19:45:51 UTC
You should always include gcc-plugin.h first when compiling plugins.
Comment 2 Bert Wesarg 2015-02-26 20:02:09 UTC
(In reply to Andrew Pinski from comment #1)
> You should always include gcc-plugin.h first when compiling plugins.

But the documentation in gcc/doc/plugins.texi only reads:

The header @file{gcc-plugin.h} must be the first gcc header to be included.

Thus it does it not required that gcc-plugin.h is the first header at all to be included. And this doesn't changed between GCC 4.9.2 and the GCC 5 snapshot.
Comment 3 Richard Biener 2015-02-27 08:26:21 UTC
Doumentation bug then.  gcc-plugin.h should be the _only_ GCC header to include.

Confirmed as documentation bug.
Comment 4 Bert Wesarg 2015-02-27 08:56:47 UTC
(In reply to Richard Biener from comment #3)
> Doumentation bug then.  gcc-plugin.h should be the _only_ GCC header to
> include.
> 

So inttypes.h is considered a GCC header than? And even if GCC mandates that gcc-plugin.h should be the first header to include in a compilation unit, how should this work in a autoconf projects which uses AC_CONFIG_HEADER, because they also mandate that this header should be the first header to include (from http://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers):

The package should ‘#include’ the configuration header file before any other header files, to prevent inconsistencies in declarations (for example, if it redefines const).