From 7bee8fd801b4495e3b292f0c3ac3440661187173 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Fri, 29 Jul 2022 00:19:59 +0200 Subject: [PATCH] P2465R3 Standard Library Modules std and std.compat --- source/basic.tex | 10 +++++--- source/declarations.tex | 14 ++++++++--- source/expressions.tex | 12 +++++---- source/lib-intro.tex | 56 +++++++++++++++++++++++++++++++++++++++++ source/support.tex | 1 + 5 files changed, 80 insertions(+), 13 deletions(-) diff --git a/source/basic.tex b/source/basic.tex index ad85305be3..ba765a09d4 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -3876,12 +3876,14 @@ or any other names that the library uses to declare these names. Thus, a \grammarterm{new-expression}, \grammarterm{delete-expression}, or function call that refers to one of -these functions without importing or including the header \libheaderref{new} is -well-formed. However, referring to \tcode{std} +these functions without importing or including the header \libheaderref{new} +or importing a \Cpp{} library module\iref{std.modules} +is well-formed. However, referring to \tcode{std} or \tcode{std::size_t} or \tcode{std::align_val_t} -is ill-formed unless the name has been declared -by importing or including the appropriate header. +is ill-formed unless +a standard library declaration\iref{cstddef.syn,new.syn,std.modules} +of that name precedes\iref{basic.lookup.general} the use of that name. \end{note} Allocation and/or deallocation functions may also be declared and defined for any diff --git a/source/declarations.tex b/source/declarations.tex index 8bb280b91c..8df1c2cd06 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -1901,6 +1901,10 @@ the deduced type $\mathtt{T}'$ replacing \tcode{T} is determined using the rules for template argument deduction. +If the initialization is copy-list-initialization, +a declaration of \tcode{std::initializer_list} +shall precede\iref{basic.lookup.general} +the \grammarterm{placeholder-type-specifier}. Obtain \tcode{P} from \tcode{T} by replacing the occurrences of \opt{\grammarterm{type-constraint}} \keyword{auto} either with @@ -5653,10 +5657,12 @@ corresponding parameter to be a non-deduced context\iref{temp.deduct.call}. \end{note} The template -\tcode{std::initializer_list} is not predefined; if the header -\tcode{} is not imported or included prior to a use of -\tcode{std::initializer_list} --- even an implicit use in which the type is not -named\iref{dcl.spec.auto} --- the program is ill-formed. +\tcode{std::initializer_list} is not predefined; +if a standard library declaration\iref{initializer.list.syn,std.modules} +of \tcode{std::initializer_list} is not reachable from\iref{module.reach} +a use of \tcode{std::initializer_list} --- +even an implicit use in which the type is not named\iref{dcl.spec.auto} --- +the program is ill-formed. \pnum List-initialization of an object or reference of type \tcode{T} is defined as follows: diff --git a/source/expressions.tex b/source/expressions.tex index bbae186efd..771923fd34 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -3939,9 +3939,10 @@ \end{example} \pnum -If the header \libheaderref{typeinfo} -is not imported or included prior -to a use of \keyword{typeid}, the program is ill-formed. +The type \tcode{std::type_info}\iref{type.info} is not predefined; +if a standard library declaration\iref{typeinfo.syn,std.modules} of +\tcode{std::type_info} does not precede\iref{basic.lookup.general} +a \tcode{typeid} expression, the program is ill-formed. \pnum \begin{note} @@ -6429,8 +6430,9 @@ \tcode{std::weak_ordering}, and \tcode{std::partial_ordering}) are not predefined; -if the header \libheaderref{compare} -is not imported or included prior to a use of such a class type -- +if a standard library declaration\iref{compare.syn,std.modules} +of such a class type does not precede\iref{basic.lookup.general} +a use of that type -- even an implicit use in which the type is not named (e.g., via the \keyword{auto} specifier\iref{dcl.spec.auto} in a defaulted three-way comparison\iref{class.spaceship} diff --git a/source/lib-intro.tex b/source/lib-intro.tex index 39dd9e1a7d..da95382659 100644 --- a/source/lib-intro.tex +++ b/source/lib-intro.tex @@ -1363,6 +1363,62 @@ \tcode{wscanf_s} \\ \end{multicolfloattable} +\rSec3[std.modules]{Modules} + +\pnum +The \Cpp{} standard library provides +the following \defn{\Cpp{} library modules}. + +\pnum +The named module \tcode{std} exports declarations in namespace \tcode{std} +that are provided by the importable \Cpp{} library headers +(\tref{headers.cpp} or the subset provided by a freestanding implementation) +and the \Cpp{} headers for C library facilities~(\tref{headers.cpp.c}). +It additionally exports declarations in the global namespace +for the storage allocation and deallocation functions +that are provided by \libheaderref{new}. + +\pnum +The named module \tcode{std.compat} exports the same declarations as +the named module \tcode{std}, and +additionally exports declarations in the global namespace +corresponding to the declarations in namespace \tcode{std} +that are provided by +the \Cpp{} headers for C library facilities~(\tref{headers.cpp.c}). + +\pnum +It is unspecified to which module a declaration in the standard library +is attached. +\begin{note} +Implementations are required to ensure that mixing +\tcode{\#include} and \tcode{import} does not result in +conflicting attachments\iref{basic.link}. +\end{note} +\recommended +Implementations should ensure such attachments do not preclude +further evolution or decomposition of the standard library modules. + +\pnum +A declaration in the standard library denotes the same entity regardless of +whether it was made reachable through +including a header, +importing a header unit, or +importing a \Cpp{} library module. + +\pnum +\recommended +Implementations should avoid exporting any other declarations +from the \Cpp{} library modules. + +\begin{note} +Like all named modules, the \Cpp{} library modules +do not make macros visible\iref{module.import}, such as +\tcode{assert}\iref{cassert.syn}, +\tcode{errno}\iref{cerrno.syn}, +\tcode{offsetof}\iref{cstddef.syn}, and +\tcode{va_arg}\iref{cstdarg.syn}. +\end{note} + \rSec3[compliance]{Freestanding implementations} \indextext{implementation!freestanding|(}% diff --git a/source/support.tex b/source/support.tex index 3ec63fb3c2..9495257e24 100644 --- a/source/support.tex +++ b/source/support.tex @@ -664,6 +664,7 @@ #define @\defnlibxname{cpp_lib_math_special_functions}@ 201603L // also in \libheader{cmath} #define @\defnlibxname{cpp_lib_mdspan}@ 202207L // also in \libheader{mdspan} #define @\defnlibxname{cpp_lib_memory_resource}@ 201603L // also in \libheader{memory_resource} +#define @\defnlibxname{cpp_lib_modules}@ 202207L #define @\defnlibxname{cpp_lib_move_only_function}@ 202110L // also in \libheader{functional} #define @\defnlibxname{cpp_lib_node_extract}@ 201606L // also in \libheader{map}, \libheader{set}, \libheader{unordered_map}, \libheader{unordered_set}