When the integrated preprocessor is not used (due to -no-integrated-cpp,
-save-temps, -E, etc), the generated .h.gch file appears to be a valid
precompiled header file, but it does not #define the preprocessor guards (and
perhaps other symbols) from the files it brought in.  This causes duplicate
symbols:

% gcc-4.3.3  -v -no-integrated-cpp -o stdafx.h.gch stdafx.h
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../gcc-4.3.3/configure
--prefix=/ati/devel/tools/gcc-4.3.3/install/linux --enable-shared
--enable-threads --enable-languages=c,c++
--with-gmp=/ati/devel/tools/gmp-4.2/install/linux
--with-mpfr=/ati/devel/tools/mpfr-2.3.1/install/linux : (reconfigured)
../../gcc-4.3.3/configure --prefix=/ati/devel/tools/gcc-4.3.3/install/linux
--enable-shared --enable-threads --enable-languages=c,c++
--with-gmp=/ati/devel/tools/gmp-4.2/install/linux
--with-mpfr=/ati/devel/tools/mpfr-2.3.1/install/linux : (reconfigured)
../../gcc-4.3.3/configure --prefix=/ati/devel/tools/gcc-4.3.3/install/linux
--enable-shared --enable-threads --enable-languages=c,c++
--with-gmp=/ati/devel/tools/gmp-4.2/install/linux
--with-mpfr=/ati/devel/tools/mpfr-2.3.1/install/linux
Thread model: posix
gcc version 4.3.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-no-integrated-cpp' '-o' 'stdafx.h.gch'
'-mtune=generic'

/ati/devel/tools/gcc-4.3.3/install/linux/libexec/gcc/i686-pc-linux-gnu/4.3.3/cc1
-E -quiet -v stdafx.h -mtune=generic -o /tmp/ccnbPxzf.i
ignoring nonexistent directory
"/ati/devel/tools/gcc-4.3.3/install/linux/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /ati/devel/tools/gcc-4.3.3/install/linux/include

/ati/devel/tools/gcc-4.3.3/install/linux/lib/gcc/i686-pc-linux-gnu/4.3.3/include

/ati/devel/tools/gcc-4.3.3/install/linux/lib/gcc/i686-pc-linux-gnu/4.3.3/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-no-integrated-cpp' '-o' 'stdafx.h.gch'
'-mtune=generic'

/ati/devel/tools/gcc-4.3.3/install/linux/libexec/gcc/i686-pc-linux-gnu/4.3.3/cc1
-fpreprocessed /tmp/ccnbPxzf.i -quiet -dumpbase stdafx.h -mtune=generic
-auxbase stdafx -version -o /tmp/ccGZpv2j.s --output-pch= stdafx.h.gch
GNU C (GCC) version 4.3.3 (i686-pc-linux-gnu)
        compiled by GNU C version 4.3.3, GMP version 4.2, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 49856469fbae50dcb90f9b2de0dd77b2

% file stdafx.h.gch
stdafx.h.gch: GCC precompiled header (version 013) for C

% gcc-4.3.3 -v -c -o pchtest.o pchtest.c
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../gcc-4.3.3/configure
--prefix=/ati/devel/tools/gcc-4.3.3/install/linux --enable-shared
--enable-threads --enable-languages=c,c++
--with-gmp=/ati/devel/tools/gmp-4.2/install/linux
--with-mpfr=/ati/devel/tools/mpfr-2.3.1/install/linux : (reconfigured)
../../gcc-4.3.3/configure --prefix=/ati/devel/tools/gcc-4.3.3/install/linux
--enable-shared --enable-threads --enable-languages=c,c++
--with-gmp=/ati/devel/tools/gmp-4.2/install/linux
--with-mpfr=/ati/devel/tools/mpfr-2.3.1/install/linux : (reconfigured)
../../gcc-4.3.3/configure --prefix=/ati/devel/tools/gcc-4.3.3/install/linux
--enable-shared --enable-threads --enable-languages=c,c++
--with-gmp=/ati/devel/tools/gmp-4.2/install/linux
--with-mpfr=/ati/devel/tools/mpfr-2.3.1/install/linux
Thread model: posix
gcc version 4.3.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'pchtest.o' '-mtune=generic'

/ati/devel/tools/gcc-4.3.3/install/linux/libexec/gcc/i686-pc-linux-gnu/4.3.3/cc1
-quiet -v pchtest.c -quiet -dumpbase pchtest.c -mtune=generic -auxbase-strip
pchtest.o -version -o /tmp/cc11Ilvb.s
ignoring nonexistent directory
"/ati/devel/tools/gcc-4.3.3/install/linux/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /ati/devel/tools/gcc-4.3.3/install/linux/include

/ati/devel/tools/gcc-4.3.3/install/linux/lib/gcc/i686-pc-linux-gnu/4.3.3/include

/ati/devel/tools/gcc-4.3.3/install/linux/lib/gcc/i686-pc-linux-gnu/4.3.3/include-fixed
 /usr/include
End of search list.
GNU C (GCC) version 4.3.3 (i686-pc-linux-gnu)
        compiled by GNU C version 4.3.3, GMP version 4.2, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 49856469fbae50dcb90f9b2de0dd77b2
In file included from pchtest.c:2:
decls.h:3: error: redefinition of ‘struct Foo’
make: *** [pchtest.o] Error 1

/****decls.h****/
#if !defined(DECLS_H)
#define DECLS_H
struct Foo {};
#endif

/****stdafx.h****/
#if !defined(STDAFX_H)
#define STDAFX_H
#include "decls.h"
#endif

/****pchtest.c****/
#include "stdafx.h"
#include "decls.h"

int main(void) { return 0; }


-- 
           Summary: Generated GCH for c++ file fails to honor include guards
                    with -no-integrated-cpp
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: pch
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sacolcor at provide dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40215

Reply via email to