Bug 13071 - no easy way to exclude backward C++ headers from include path
Summary: no easy way to exclude backward C++ headers from include path
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 3.3.2
: P3 enhancement
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-16 12:47 UTC by Debian GCC Maintainers
Modified: 2022-03-18 10:48 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-31 20:30:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Debian GCC Maintainers 2003-11-16 12:47:49 UTC
[forwarded from http://bugs.debian.org/211586]

$ cat bug-211586.cc 
extern "C" {
#include <complex.h>
}

on a Linux system this is supposed to include /usr/include/complex.h, but
/usr/include/c++/3.3/backward/complex.h is found. There is currently no way to
exclude the deprecated or antiquated header files from the include path.
Comment 1 Paolo Carlini 2003-11-16 17:29:00 UTC
"There is currently no way" seems to me way (punt intended :) too strong!
What about:

 -nostdinc++ -I/usr/include/c++/3.3.2 -I/usr/include/c++/3.3.2/i686-pc-linux-gnu

??
Comment 2 Matthias Klose 2003-11-16 18:37:04 UTC
Subject: Re:  no way to exclude backward C++ headers from include path

paolo at gcc dot gnu dot org writes:
> 
> ------- Additional Comments From paolo at gcc dot gnu dot org  2003-11-16 17:29 -------
> "There is currently no way" seems to me way (punt intended :) too strong!
> What about:
> 
>  -nostdinc++ -I/usr/include/c++/3.3.2 -I/usr/include/c++/3.3.2/i686-pc-linux-gnu

maybe too strong, but not very portable or user friendly. the user needs at least to
know the exact version of gcc he uses, if configured with
--with-gxx-include-dir, the name of this directory and the system
alias that gcc was configured for. something like -backwardstdcinc++
to explicitely enable the backward include dir would be useful.
Comment 3 Andrew Pinski 2003-11-26 08:42:42 UTC
confirmed, changed summary based on the fact there is a way but it is not easy.
Comment 4 Andrew Pinski 2003-12-04 18:34:37 UTC
Well it is bad practice to wrap any include with `extern "c"'.
Comment 5 Benjamin Kosnik 2007-02-06 18:32:04 UTC
Solving for C++0x.
Comment 6 Jonathan Wakely 2009-06-23 18:32:00 UTC
This seems to be fixed in all open branches (4.3+)
Comment 7 Andrew Pinski 2021-09-06 06:56:46 UTC
Isn't doing the extern "C" around standard C++ headers declared by the C++ standard as undefined behavior?
Comment 8 Harald van Dijk 2021-09-06 07:53:23 UTC
(In reply to Andrew Pinski from comment #7)
> Isn't doing the extern "C" around standard C++ headers declared by the C++
> standard as undefined behavior?

It is (as is doing extern "C++" around standard C++ headers, for that matter), but <complex.h> only became a standard C++ header in C++11. This bug is from 2003 and the comment before yours was from 2009, so I think <complex.h> was not a standard C++ header yet.
Comment 9 Jonathan Wakely 2022-03-17 11:28:35 UTC
(In reply to Harald van Dijk from comment #8)
> (In reply to Andrew Pinski from comment #7)
> > Isn't doing the extern "C" around standard C++ headers declared by the C++
> > standard as undefined behavior?
> 
> It is (as is doing extern "C++" around standard C++ headers, for that
> matter),

Where does it say that?

> but <complex.h> only became a standard C++ header in C++11. This
> bug is from 2003 and the comment before yours was from 2009, so I think
> <complex.h> was not a standard C++ header yet.

Agreed. But there is no complex.h in the backward directory now.

The contents of that directory are:

auto_ptr.h  backward_warning.h  binders.h  hash_fun.h  hash_map  hash_set  hashtable.h  strstream

The <strstream> header is required for standard conformance, so excluding that directory would make it impossible to use that standard header. The other headers seem unlikely to conflict with any headers in /usr/include (which was the original subject of this PR).

Can we close this now?
Comment 10 Harald van Dijk 2022-03-17 11:56:50 UTC
(In reply to Jonathan Wakely from comment #9)
> (In reply to Harald van Dijk from comment #8)
> > (In reply to Andrew Pinski from comment #7)
> > > Isn't doing the extern "C" around standard C++ headers declared by the C++
> > > standard as undefined behavior?
> > 
> > It is (as is doing extern "C++" around standard C++ headers, for that
> > matter),
> 
> Where does it say that?

It's the exact same rule as for extern "C", [using.headers]p3. (And yes, it does make a difference to not having extern "C++" around it and can cause breakage, this is not purely hypothetical, but it's much less likely to cause problems than extern "C".)

> > but <complex.h> only became a standard C++ header in C++11. This
> > bug is from 2003 and the comment before yours was from 2009, so I think
> > <complex.h> was not a standard C++ header yet.
> 
> Agreed. But there is no complex.h in the backward directory now.
>[...]
> Can we close this now?

Testing with GCC 11 as provided by Ubuntu, including <complex.h> will cause GCC's c++/11/complex.h to be included, both in C++03 and in C++11 modes, but in C++03 it just delegates to glibc's <complex.h>. To me, that looks like it's fixed.
Comment 11 Jonathan Wakely 2022-03-17 13:54:48 UTC
[using.headers] says you can't include a header inside a declaration or definition. A linkage specification is a declaration in terms of the C++ grammar, but I'm not sure that's what [using.headers] means. It doesn't actually declare anything.

I'll open an LWG issue to get clarification.

Anyway, let's close this.
Comment 12 Jonathan Wakely 2022-03-18 10:48:34 UTC
(In reply to Jonathan Wakely from comment #11)
> I'll open an LWG issue to get clarification.

LWG agrees that it's ill-formed (no diagnostic required) to include standard headers inside a linkage-specification.

Libstdc++ tries to makes it work as QoI, e.g. r12-4367-gc1b6c360fcf3fc