Bug 86674 - -W(no)-error=invalid-pch does not affect incorrect language warning
Summary: -W(no)-error=invalid-pch does not affect incorrect language warning
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: pch (show other bugs)
Version: 8.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2018-07-25 14:02 UTC by Jason Wyatt
Modified: 2020-11-12 14:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Wyatt 2018-07-25 14:02:12 UTC
-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
Comment 1 GCC Commits 2020-11-12 14:02:24 UTC
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.
Comment 2 Jeffrey A. Law 2020-11-12 14:03:38 UTC
Should be fixed on the trunk