From 57948ece25b90ce301abf5177b6a9e4850fbb852 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Sun, 24 Nov 2024 22:10:41 +0100 Subject: [PATCH] P3247R2 Deprecate the notion of trivial types --- source/basic.tex | 5 ----- source/classes.tex | 19 +++++-------------- source/containers.tex | 19 ++++++++++--------- source/future.tex | 37 +++++++++++++++++++++++++++++++++++++ source/meta.tex | 10 ---------- source/strings.tex | 3 ++- source/support.tex | 3 ++- 7 files changed, 56 insertions(+), 40 deletions(-) diff --git a/source/basic.tex b/source/basic.tex index c1708584a4..d4f60f7304 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -4921,11 +4921,6 @@ Scalar types, trivially copyable class types\iref{class.prop}, arrays of such types, and cv-qualified versions of these types are collectively called \defnadjx{trivially copyable}{types}{type}. -\label{term.trivial.type}% -Scalar types, trivial class types\iref{class.prop}, -arrays of such types, and cv-qualified versions of these -types are collectively called -\defnadjx{trivial}{types}{type}. \label{term.standard.layout.type}% Scalar types, standard-layout class types\iref{class.prop}, arrays of such types, and diff --git a/source/classes.tex b/source/classes.tex index a209ff34c8..b2a2296a09 100644 --- a/source/classes.tex +++ b/source/classes.tex @@ -172,15 +172,6 @@ \item that has a trivial, non-deleted destructor\iref{class.dtor}. \end{itemize} -\pnum -A \defnadj{trivial}{class} is a class that is trivially copyable and -has one or more eligible default constructors\iref{class.default.ctor}, -all of which are trivial. -\begin{note} -In particular, a trivially copyable or trivial class does not have -virtual functions or virtual base classes. -\end{note} - \pnum A class \tcode{S} is a \defnadj{standard-layout}{class} if it: \begin{itemize} @@ -272,25 +263,25 @@ \pnum \begin{example} \begin{codeblock} -struct N { // neither trivial nor standard-layout +struct N { // neither trivially copyable nor standard-layout int i; int j; virtual ~N(); }; -struct T { // trivial but not standard-layout +struct T { // trivially copyable but not standard-layout int i; private: int j; }; -struct SL { // standard-layout but not trivial +struct SL { // standard-layout but not trivially copyable int i; int j; ~SL(); }; -struct POD { // both trivial and standard-layout +struct POD { // both trivially copyable and standard-layout int i; int j; }; @@ -5942,7 +5933,7 @@ B bobj; // definition of \tcode{bobj} extern X xobj; -int* p3 = &xobj.i; // OK, \tcode{X} is a trivial class +int* p3 = &xobj.i; // OK, all constructors of \tcode{X} are trivial X xobj; \end{codeblock} For another example, diff --git a/source/containers.tex b/source/containers.tex index 09d642b600..59c36aa8a9 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -9537,8 +9537,9 @@ \pnum For any $\tcode{N} > 0$, -if \tcode{is_trivial_v} is \tcode{false}, then -no \tcode{inplace_vector} member functions +if \tcode{T} is not trivially copyable or +\tcode{is_trivially_default_constructible_v} is \tcode{false}, +then no \tcode{inplace_vector} member functions are usable in constant expressions. \pnum @@ -20618,13 +20619,13 @@ \end{codeblock} \pnum -Each of \tcode{layout_left}, \tcode{layout_right}, and \tcode{layout_stride} -meets the layout mapping policy requirements and is a trivial type. - -\pnum -Each specialization of -\tcode{layout_left_padded} and \tcode{layout_right_padded} -meets the layout mapping policy requirements and is a trivial type. +Each of \tcode{layout_left}, \tcode{layout_right}, and \tcode{layout_stride}, +as well as each specialization of +\tcode{layout_left_padded} and \tcode{layout_right_padded}, +meets the layout mapping policy requirements and is a trivially copyable type. +Furthermore, +\tcode{is_trivially_default_constructible_v} is \tcode{true} +for any such type \tcode{T}. \rSec4[mdspan.layout.left]{Class template \tcode{layout_left::mapping}} diff --git a/source/future.tex b/source/future.tex index 4eab361bf9..b47d9ed515 100644 --- a/source/future.tex +++ b/source/future.tex @@ -286,6 +286,8 @@ \begin{codeblock} namespace std { + template struct is_trivial; + template constexpr bool is_trivial_v = is_trivial::value; template struct is_pod; template constexpr bool is_pod_v = is_pod::value; template // \seebelow @@ -304,6 +306,17 @@ any of the templates defined in this subclause is undefined, unless explicitly permitted by the specification of the corresponding template. +\pnum +\label{term.trivial.type}% +A \defnadj{trivial}{class} is a class that is trivially copyable and +has one or more eligible default constructors, all of which are trivial. +\begin{note} +In particular, +a trivial class does not have virtual functions or virtual base classes. +\end{note} +A \defnadj{trivial}{type} is a scalar type, a trivial class, +an array of such a type, or a cv-qualified version of one of these types.. + \pnum \indextext{POD}% A \term{POD class} is a class that is both a trivial class and a @@ -311,6 +324,30 @@ (or array thereof). A \term{POD type} is a scalar type, a POD class, an array of such a type, or a cv-qualified version of one of these types. +\indexlibraryglobal{is_trivial}% +\begin{itemdecl} +template struct is_trivial; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\expects +\tcode{remove_all_extents_t} shall be a complete type or \cv{} \keyword{void}. + +\pnum +\remarks +\tcode{is_trivial} is a \oldconcept{UnaryTypeTrait}\iref{meta.rqmts} +with a base characteristic of \tcode{true_type} +if \tcode{T} is a trivial type, +and \tcode{false_type} otherwise. + +\pnum +\begin{note} +It is unspecified +whether a closure type\iref{expr.prim.lambda.closure} is a trivial type. +\end{note} +\end{itemdescr} + \indexlibraryglobal{is_pod}% \begin{itemdecl} template struct is_pod; diff --git a/source/meta.tex b/source/meta.tex index ec59b440b8..6114f69ab0 100644 --- a/source/meta.tex +++ b/source/meta.tex @@ -192,7 +192,6 @@ // \ref{meta.unary.prop}, type properties template struct is_const; template struct is_volatile; - template struct is_trivial; template struct is_trivially_copyable; template struct is_standard_layout; template struct is_empty; @@ -430,8 +429,6 @@ constexpr bool @\libglobal{is_const_v}@ = is_const::value; template constexpr bool @\libglobal{is_volatile_v}@ = is_volatile::value; - template - constexpr bool @\libglobal{is_trivial_v}@ = is_trivial::value; template constexpr bool @\libglobal{is_trivially_copyable_v}@ = is_trivially_copyable::value; template @@ -832,13 +829,6 @@ \tcode{T} is volatile-qualified\iref{basic.type.qualifier} & \\ \rowsep -\indexlibraryglobal{is_trivial}% -\tcode{template}\br - \tcode{struct is_trivial;} & - \tcode{T} is a trivial type\iref{term.trivial.type} & - \tcode{remove_all_extents_t} shall be a complete - type or \cv{}~\keyword{void}. \\ \rowsep - \indexlibraryglobal{is_trivially_copyable}% \tcode{template}\br \tcode{struct is_trivially_copyable;} & diff --git a/source/strings.tex b/source/strings.tex index 1e075915ae..f9591bd9cb 100644 --- a/source/strings.tex +++ b/source/strings.tex @@ -5,7 +5,8 @@ \pnum This Clause describes components for manipulating sequences of -any non-array trivial standard-layout\iref{term.standard.layout.type} type. +any non-array trivially copyable standard-layout\iref{term.standard.layout.type} type \tcode{T} +where \tcode{is_trivially_default_constructible_v} is \tcode{true}. Such types are called \defnx{char-like types}{char-like type}, and objects of char-like types are called \defnx{char-like objects}{char-like object} or diff --git a/source/support.tex b/source/support.tex index 28c15ac913..510c26c288 100644 --- a/source/support.tex +++ b/source/support.tex @@ -333,9 +333,10 @@ \pnum The type \indexlibraryglobal{max_align_t}% -\tcode{max_align_t} is a trivial standard-layout type whose alignment requirement +\tcode{max_align_t} is a trivially copyable standard-layout type whose alignment requirement is at least as great as that of every scalar type, and whose alignment requirement is supported in every context\iref{basic.align}. +\tcode{std::is_trivially_default_constructible_v} is \tcode{true}. \xrefc{7.19}