https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91999
Bug ID: 91999 Summary: pch_open_file picks up a first found precompiled header even if it's not suitable Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: pch Assignee: unassigned at gcc dot gnu.org Reporter: guriev-ns at ya dot ru Target Milestone: --- In the following example g++ uses C precompiled header if it exists, although there is a C++ precompiled header nearby in the all.h.gch directory. The error occurs when -Winvalid-pch is set and there is a precompiled header for C in .gch directory. mymedia@barberry:/tmp/tmp.uz5iSoQUFL$ head * ==> all.h <== #ifndef __cplusplus # include <stdio.h> #else # include <iostream> #endif ==> t1.c <== #include "all.h" int main (void) { printf("Hello!\n"); return 0; } ==> t2.C <== #include "all.h" int main() { std::cout << "Hello!" << std::endl; } mymedia@barberry:/tmp/tmp.uz5iSoQUFL$ mkdir all.h.gch mymedia@barberry:/tmp/tmp.uz5iSoQUFL$ gcc-9 -Werror -Wall -Wextra -x c-header all.h -o all.h.gch/.c mymedia@barberry:/tmp/tmp.uz5iSoQUFL$ g++-9 -Werror -Wall -Wextra -x c++-header all.h -o all.h.gch/.c++ mymedia@barberry:/tmp/tmp.uz5iSoQUFL$ gcc-9 -Werror -Wall -Wextra -Winvalid-pch t1.c -o t1.out mymedia@barberry:/tmp/tmp.uz5iSoQUFL$ g++-9 -Werror -Wall -Wextra -Winvalid-pch t2.C -o t2.out t2.C:1:17: error: all.h.gch/.c: not for GNU C++14 [-Werror] 1 | #include "all.h" | ^ cc1plus: all warnings being treated as errors mymedia@barberry:/tmp/tmp.uz5iSoQUFL$ gcc-9 -v Using built-in specs. COLLECT_GCC=gcc-9 COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:hsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 9.2.1-8' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 9.2.1 20190909 (Debian 9.2.1-8)