Skip to content

Commit

Permalink
[libc++][modules] Attach declarations to the global module.
Browse files Browse the repository at this point in the history
Declarations in the global module fragment (the included headers) are attached
to the global module. The using declarations in the module std and std.compat
were attached to their module.

This violates

  [basic.link]/10
  If two declarations of an entity are attached to different modules, the
  program is ill-formed; no diagnostic is required if neither is reachable from
  the other.

Instead attach the delarations in the module to the global module by using a
linkage-specification. ([module.unit]/7)

Thanks to @DanielaE for pointing out this issue.
  • Loading branch information
mordante committed May 20, 2024
1 parent 82c5d35 commit 4f17ea3
Show file tree
Hide file tree
Showing 134 changed files with 179 additions and 174 deletions.
11 changes: 11 additions & 0 deletions libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,17 @@ typedef __char32_t char32_t;
# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
// clang-format on

// Named declarations included in the headers are part of the global module
// fragment. These declarations are attached to the global module. The using
// declarations in the module should also attach their declarations to the
// global module. This is done by using a linkage specification.
# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1800
// Clang-17 does not support extern "C++" export
# define _LIBCPP_MODULE_EXPORT export
# else
# define _LIBCPP_MODULE_EXPORT extern "C++" export
# endif

# if __has_attribute(__enable_if__)
# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
# endif
Expand Down
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cassert.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
// This module exports nothing.
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cctype.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::isalnum _LIBCPP_USING_IF_EXISTS;
using ::isalpha _LIBCPP_USING_IF_EXISTS;
using ::isblank _LIBCPP_USING_IF_EXISTS;
Expand All @@ -22,4 +22,4 @@ export {
using ::isxdigit _LIBCPP_USING_IF_EXISTS;
using ::tolower _LIBCPP_USING_IF_EXISTS;
using ::toupper _LIBCPP_USING_IF_EXISTS;
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cerrno.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
// This module exports nothing.
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cfenv.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
// types
using ::fenv_t _LIBCPP_USING_IF_EXISTS;
using ::fexcept_t _LIBCPP_USING_IF_EXISTS;
Expand All @@ -26,4 +26,4 @@ export {
using ::feholdexcept _LIBCPP_USING_IF_EXISTS;
using ::fesetenv _LIBCPP_USING_IF_EXISTS;
using ::feupdateenv _LIBCPP_USING_IF_EXISTS;
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cfloat.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
// This module exports nothing.
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cinttypes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::imaxdiv_t _LIBCPP_USING_IF_EXISTS;

using ::imaxabs _LIBCPP_USING_IF_EXISTS;
Expand All @@ -22,4 +22,4 @@ export {

// div is conditionally here, but always present in cstdlib.cppm. To avoid
// conflicing declarations omit the using here.
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/climits.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
// This module exports nothing.
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/clocale.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
using ::lconv _LIBCPP_USING_IF_EXISTS;

using ::localeconv _LIBCPP_USING_IF_EXISTS;
using ::setlocale _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LOCALIZATION
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cmath.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::double_t _LIBCPP_USING_IF_EXISTS;
using ::float_t _LIBCPP_USING_IF_EXISTS;

Expand Down Expand Up @@ -265,4 +265,4 @@ export {
using ::signbit _LIBCPP_USING_IF_EXISTS;

// [sf.cmath], mathematical special functions
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/csetjmp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::jmp_buf _LIBCPP_USING_IF_EXISTS;
using ::longjmp _LIBCPP_USING_IF_EXISTS;
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/csignal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::sig_atomic_t _LIBCPP_USING_IF_EXISTS;

// [support.signal], signal handlers
using ::signal _LIBCPP_USING_IF_EXISTS;

using ::raise _LIBCPP_USING_IF_EXISTS;
} // export
} // _LIBCPP_MODULE_EXPORT
2 changes: 1 addition & 1 deletion libcxx/modules/std.compat/cstdarg.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
//
//===----------------------------------------------------------------------===//

export { using ::va_list _LIBCPP_USING_IF_EXISTS; } // export
_LIBCPP_MODULE_EXPORT { using ::va_list _LIBCPP_USING_IF_EXISTS; } // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cstddef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::max_align_t _LIBCPP_USING_IF_EXISTS;
using ::nullptr_t;
using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
Expand All @@ -19,4 +19,4 @@ export {
// function templates described in [support.types.byteops]. ...

// [support.types.byteops], byte type operations
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cstdint.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
// signed
using ::int8_t _LIBCPP_USING_IF_EXISTS;
using ::int16_t _LIBCPP_USING_IF_EXISTS;
Expand Down Expand Up @@ -47,4 +47,4 @@ export {
using ::uintmax_t _LIBCPP_USING_IF_EXISTS;

using ::uintptr_t _LIBCPP_USING_IF_EXISTS;
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cstdio.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::FILE _LIBCPP_USING_IF_EXISTS;
using ::fpos_t _LIBCPP_USING_IF_EXISTS;
using ::size_t _LIBCPP_USING_IF_EXISTS;
Expand Down Expand Up @@ -58,4 +58,4 @@ export {
using ::vsprintf _LIBCPP_USING_IF_EXISTS;
using ::vsscanf _LIBCPP_USING_IF_EXISTS;

} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cstdlib.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::div_t _LIBCPP_USING_IF_EXISTS;
using ::ldiv_t _LIBCPP_USING_IF_EXISTS;
using ::lldiv_t _LIBCPP_USING_IF_EXISTS;
Expand Down Expand Up @@ -69,4 +69,4 @@ export {
using ::ldiv _LIBCPP_USING_IF_EXISTS;
using ::lldiv _LIBCPP_USING_IF_EXISTS;

} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cstring.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::size_t _LIBCPP_USING_IF_EXISTS;

using ::memchr _LIBCPP_USING_IF_EXISTS;
Expand All @@ -33,4 +33,4 @@ export {
using ::strtok _LIBCPP_USING_IF_EXISTS;
using ::strxfrm _LIBCPP_USING_IF_EXISTS;

} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/ctime.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
using ::clock_t _LIBCPP_USING_IF_EXISTS;
using ::size_t _LIBCPP_USING_IF_EXISTS;
using ::time_t _LIBCPP_USING_IF_EXISTS;
Expand All @@ -25,4 +25,4 @@ export {
using ::strftime _LIBCPP_USING_IF_EXISTS;
using ::time _LIBCPP_USING_IF_EXISTS;
using ::timespec_get _LIBCPP_USING_IF_EXISTS;
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cuchar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
// Note the Standard does not mark these symbols optional, but libc++'s header
// does. So this seems strictly not to be conforming.

Expand All @@ -25,4 +25,4 @@ export {
using ::c16rtomb _LIBCPP_USING_IF_EXISTS;
using ::mbrtoc32 _LIBCPP_USING_IF_EXISTS;
using ::c32rtomb _LIBCPP_USING_IF_EXISTS;
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cwchar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
using ::size_t _LIBCPP_USING_IF_EXISTS;
Expand Down Expand Up @@ -77,4 +77,4 @@ export {
using ::wcrtomb _LIBCPP_USING_IF_EXISTS;
using ::wcsrtombs _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
} // export
} // _LIBCPP_MODULE_EXPORT
4 changes: 2 additions & 2 deletions libcxx/modules/std.compat/cwctype.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export {
_LIBCPP_MODULE_EXPORT {
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using ::wctrans_t _LIBCPP_USING_IF_EXISTS;
using ::wctype_t _LIBCPP_USING_IF_EXISTS;
Expand All @@ -32,4 +32,4 @@ export {
using ::wctrans _LIBCPP_USING_IF_EXISTS;
using ::wctype _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
} // export
} // _LIBCPP_MODULE_EXPORT
2 changes: 1 addition & 1 deletion libcxx/modules/std/algorithm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
namespace ranges {
// [algorithms.results], algorithm result types
using std::ranges::in_found_result;
Expand Down
3 changes: 1 addition & 2 deletions libcxx/modules/std/any.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {

_LIBCPP_MODULE_EXPORT namespace std {
// [any.bad.any.cast], class bad_any_cast
using std::bad_any_cast;

Expand Down
3 changes: 1 addition & 2 deletions libcxx/modules/std/array.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {

_LIBCPP_MODULE_EXPORT namespace std {
// [array], class template array
using std::array;

Expand Down
3 changes: 1 addition & 2 deletions libcxx/modules/std/atomic.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {

_LIBCPP_MODULE_EXPORT namespace std {
// [atomics.order], order and consistency
using std::memory_order _LIBCPP_USING_IF_EXISTS;
using std::memory_order_acq_rel _LIBCPP_USING_IF_EXISTS;
Expand Down
2 changes: 1 addition & 1 deletion libcxx/modules/std/barrier.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
#ifndef _LIBCPP_HAS_NO_THREADS
using std::barrier;
#endif // _LIBCPP_HAS_NO_THREADS
Expand Down
2 changes: 1 addition & 1 deletion libcxx/modules/std/bit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
// [bit.cast], bit_cast
using std::bit_cast;

Expand Down
2 changes: 1 addition & 1 deletion libcxx/modules/std/bitset.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
using std::bitset;

// [bitset.operators], bitset operators
Expand Down
2 changes: 1 addition & 1 deletion libcxx/modules/std/cassert.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
// This module exports nothing.
} // namespace std
2 changes: 1 addition & 1 deletion libcxx/modules/std/cctype.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
using std::isalnum _LIBCPP_USING_IF_EXISTS;
using std::isalpha _LIBCPP_USING_IF_EXISTS;
using std::isblank _LIBCPP_USING_IF_EXISTS;
Expand Down
2 changes: 1 addition & 1 deletion libcxx/modules/std/cerrno.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
// This module exports nothing.
} // namespace std
2 changes: 1 addition & 1 deletion libcxx/modules/std/cfenv.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//

export namespace std {
_LIBCPP_MODULE_EXPORT namespace std {
// types
using std::fenv_t _LIBCPP_USING_IF_EXISTS;
using std::fexcept_t _LIBCPP_USING_IF_EXISTS;
Expand Down
Loading

0 comments on commit 4f17ea3

Please sign in to comment.