-Werror=invalid-pch does not turn warnings caused by -Winvalid-pch into errors. -Wno-error=invalid-pch does not turn errors caused by -Winvalid-pch -Werror into warnings. Context: When compiling the same prefix for multiple languages, https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html suggests that they can all co-exist in the same folder, since the compiler will search them all and choose the correct one. However this will cause https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17162. As a result, in cases where -Werror is enabled, it would be useful to turn -Winvalid-pch back into a warning. Example - the contents of the files are irrelevant, just use empty files if need be: gcc -Wall -Wextra -x c-header Prefix.h -o Prefix.h.gch/c.h gcc -Wall -Wextra -x c++-header Prefix.h -o Prefix.h.gch/c++.h gcc -Wall -Wextra -Winvalid-pch -Werror -Wno-error=invalid-pch -include Prefix.h -c Test.c gcc -Wall -Wextra -Winvalid-pch -Werror -Wno-error=invalid-pch -include Prefix.h -c Test.cpp This produces only the following output: cc1plus: error: ./Prefix.h.gch/c.h: not for GNU C++14 [-Werror] cc1plus: all warnings being treated as errors
The master branch has been updated by Jeff Law <law@gcc.gnu.org>: https://gcc.gnu.org/g:cb808c583de59ea568fd240144cd9db07272f45e commit r11-4944-gcb808c583de59ea568fd240144cd9db07272f45e Author: Nicholas Guriev <guriev-ns@ya.ru> Date: Thu Nov 12 08:59:35 2020 -0500 Specify reason of -Winvalid-pch warning gcc/c-family PR pch/86674 * c-pch.c (c_common_valid_pch): Use cpp_warning with CPP_W_INVALID_PCH reason to fix -Werror=invalid-pch and -Wno-error=invalid-pch switches. libcpp PR pch/86674 * files.c (_cpp_find_file): Use CPP_DL_NOTE not CPP_DL_ERROR in call to cpp_error.
Should be fixed on the trunk