C++ Logo

std-proposals

Advanced search

Re: [std-proposals] #includes turning into imports breaks existing usage

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 08 May 2026 12:40:28 -0700
On Friday, 8 May 2026 12:02:09 Pacific Daylight Time Rainer Deyke via Std-
Proposals wrote:
> "An importable header is a member of an implementation-defined set of
> headers that includes all importable C++ library headers (16.4.2.3)."

This excludes any third-party header. Therefore, all third party headers are
unimportable.

Aside from <assert.h>, is there any C++ Standard Library header that
*officially* reacts to predefined macros?

> gcc does not seem to look at the contents of headers to determine if
> they are importable. Determining if a header depends on external macros
> just by looking at it would be very hard, since the behavior of almost
> any header, including all headers in the standard library, can be
> changed by defining the right macros. Instead, gcc looks if the header
> has been precompiled, which has nothing to do with its content.
>
> You might claim it's my own fault for precompiling headers that are not,
> in fact, importable. To which my reply is fourfold:
>
> 1. The set of importable headers is, again, implementation-defined.
> There is nothing in the standard that forbids gcc from considering these
> headers as importable.

Correct. But that's GCC's doing, not yours by doing precompilation.

If there's a feature that could change with a macro, then either the header is
not importable or the feature is not official. If it's the former and the
compiler made it importable, then it's a compiler bug and you should report --
this includes official extensions. If it's an unofficial feature or not a feature
at all, then it's your fault for relying on it.

> 2. In the absence of documentation to the contrary, I put to you that
> the fact that gcc precompiles these headers without error message and
> then converts #includes to these headers into imports, suggests that gcc
> does, in fact, consider these headers importable.

Which of the two categories above is it? Note precompilation doesn't count.

> 3. The requirement to precompile importable headers is an implementation
> detail of gcc. A different compiler might choose to compile imported
> headers as it encounters them, with no separate precompile step. If it
> is legal for gcc to treat a precompiled header as an importable header,
> then it is also legal for a different compiler to treat the same header
> as an importable header without a precompile step.

Huh?

Each compiler's set of importable headers is its own. One of them making a
given header importable has absolutely no implication on another's behaviour.
Plus, all of this should be transparent to you. You do not need to precompile
to see it.

Precompiling is not a Standard feature and is not the same as imports.

> 4. If I can't determine if a given header is importable for a given
> compiler, much less in general, what can I do?

Nothing. The feature is transparent to you. If a header is importable and the
compiler thinks it's useful to import, it will.

> I can't even say forget
> importable headers and go back to #include, because, again, #includes
> can silently change into imports in a way that changes their behavior.

Repeating from above: if the compiler does that and breaks an official feature,
it's a bug in the compiler. If it breaks an unofficial feature, it's your bug.

> I suppose you can be argue that the intention of the "importable header"
> set is to include only the standard library and other
> implementation-provided headers, with user-defined headers categorically
> excluded. In that case the concept of importable header is mostly
> obsolete except for the few macros in the standard library that can't be
> accessed from the std module. Also, gcc is then going against the
> spirit (but not the letter) of the standard by converting #includes to
> precompiled user-defined headers into imports.

Correct.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-05-08 19:40:37