C++ Logo

std-proposals

Advanced search

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

From: Andre Kostur <andre_at_[hidden]>
Date: Fri, 8 May 2026 08:48:50 -0700
On Fri, May 8, 2026 at 8:35 AM Rainer Deyke via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Here is my understanding of the current situation:
>
> The set of importable headers is implementation-defined, and can
> potentially include all headers.

Not sure what you mean about "potentially include all headers". As
far as I know, the Standard does not claim that any arbitrary header
is importable, precisely because of things like dependencies on
macros. And note that if it's implementation-defined, then it is
highly unlikely that the implementation will claim that any arbitrary
user-defined header file is importable. (Where the examples you give
below are all user-defined headers)

> The compiler may, at its discretion, turn all #includes of importable
> headers into imports. Which, again, is potentially all headers.

Not sure where that's stated, but do note the phrase "importable
header". I would suggest that headers that depend on macros are not
importable.

> Imported headers, unlike #included headers, do not have access to the
> preprocessor state of the importing translation unit.
>
> Therefore any usage of #defines to pass data into a header is no longer
> standard-conforming, even if #include is used instead of import.
>
> Is this correct? Because if so, this breaks a lot of existing code.

No, because you're glossing over "importable header". If the header
depends on preprocessor state, then that header is not importable.

> For example:
>
> The widely used stb family of single header libraries
> (https://github.com/nothings/stb) all require a STB_*_IMPLEMENTATION
> symbol to be #defined in exactly one translation unit that #includes the
> header. The same idiom is widely used in other single-header libraries
> such as DocTest (https://github.com/doctest/doctest).
>
> Boost.Test (https://www.boost.org/library/latest/test/) uses a variation
> of the above idiom, requiring BOOST_TEST_MODULE to be #defined in
> exactly one translation unit before #including the relevant header.
> Unlike the above case, the value of BOOST_TEST_MODULE is also used to
> configure Boost.Test.
>
> Another idiom, used by SDL (https://www.libsdl.org/) for example, uses a
> variant of the X macro technique (https://en.wikipedia.org/wiki/X_macro)
> where the same header file is #included multiple times in the same
> translation unit, each time with different definitions for the macros
> that the header file calls.

All of those are user-defined headers. I don't know of any
implementation that claims that they are importable.

Received on 2026-05-08 15:49:05