Bug 91770 - warn on #includes inside extern C regions
Summary: warn on #includes inside extern C regions
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Nathan Sidwell
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
Reported: 2019-09-14 16:17 UTC by Nathan Sidwell
Modified: 2024-07-13 22:53 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2019-09-14 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Sidwell 2019-09-14 16:17:13 UTC
Add a warning to detect:
extern "C" {
#include "foo"

as that will cause problems with c++20 header-units & include translation.

Bonus points if the warning triggers only when "foo" itself contains an outer extern "C" { region.
Comment 1 Nathan Sidwell 2019-09-14 16:18:14 UTC
Related to glibc BZ 24998
Comment 2 Eric Gallager 2019-12-23 05:24:45 UTC
I wonder how hard it would be to get the interaction with -Wsystem-headers right here, given how many other issues with -Wsystem-headers there are...
Comment 3 Jonathan Wakely 2024-07-12 09:52:40 UTC
N.B. the C++ standard says it's undefined to do this for any standard header:

[using.headers] in the standard says "A translation unit shall include a header only outside of any declaration or definition"