Skip to content

[C++20][Modules] deleted definitions should be allowed in header units #60079

Closed
@kaimfrai

Description

@kaimfrai

Since non-inline external definitions in header units were disallowed in commit/335668b, using standard header units has become impractical.
In particular, the example given at https://clang.llvm.org/docs/StandardCPlusPlusModules.html#header-units

clang++ -std=c++20 -xc++-system-header --precompile iostream -o iostream.pcm

no longer compiles with current Clang 16 (tried libc++ and libstdc++) while it did work before.

Errors include but are not limited to:

libstdc++

include/c++/12/new:206:8: error: non-inline external definitions are not permitted in C++ header units
  void launder(volatile void*) = delete;
include/c++/12/type_traits:2125:27: error: non-inline external definitions are not permitted in C++ header units
      static const size_t _S_alignment = 0;

libc++

 include/c++/v1/__type_traits/aligned_union.h:29:25: error: non-inline external definitions are not permitted in C++ header units
    static const size_t value = _I0;
include/c++/v1/__functional/reference_wrapper.h:100:27: error: non-inline external definitions are not permitted in C++ header units
template <class _Tp> void ref(const _Tp&&) = delete;

Unfortunately, this issue isn't limited to libstdc++ and libc++. Not only do other headers often include standard headers, but it's entirely resonable to have = delete; in header files. They are therefore also unusable as header units. Transitioning from headers to header units is thus limited to a small subset of headers, while Clang 15 allowed many more. While I think it's the correct default to error out in these cases, I would appreciate an explicit flag that skips over this rule, at least until P1502R1 (Standard library Header Units) or P2465R3 (std module) are implemented. For example:

clang++ -std=c++20 -xc++-system-header -fallow-non-inline-external-definitions-in-header-units --precompile iostream -o iostream.pcm

Without such a flag I would find it very hard to make use of standard header units as they are implemented right now.

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions