diff --git a/source/basic.tex b/source/basic.tex index bd155ed606..5b47441bf3 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -1083,10 +1083,12 @@ The locus of a \grammarterm{class-specifier} is immediately after the \grammarterm{identifier} or \grammarterm{simple-template-id} (if any) in its \grammarterm{class-head}\iref{class.pre}. -The locus of -an \grammarterm{enum-specifier} or \grammarterm{opaque-enum-declaration} -is immediately after the \grammarterm{identifier} (if any) -in it\iref{dcl.enum}. +The locus of an \grammarterm{enum-specifier} +is immediately after +its \grammarterm{enum-head}; +the locus of an \grammarterm{opaque-enum-declaration} +is immediately after it\iref{dcl.enum}. +%FIXME: What's "it" below? What's "it" above? The locus of an \grammarterm{alias-declaration} is immediately after it. \pnum @@ -1512,18 +1514,18 @@ \pnum \indextext{scope!search}% -A \defn{search} in a scope $X$ for a name $N$ from a program point $P$ -is a single search in $X$ for $N$ from $P$ +A \defn{search} in a scope $X$ for a name $M$ from a program point $P$ +is a single search in $X$ for $M$ from $P$ unless $X$ is the scope of a class or class template $T$, in which case the following steps define the result of the search. \begin{note} The result differs only -if $N$ is a \grammarterm{conversion-function-id} or +if $M$ is a \grammarterm{conversion-function-id} or if the single search would find nothing. \end{note} \pnum -The \defn{lookup set} for $N$ in $C$, called $S(N,C)$, +The \defn{lookup set} for a name $N$ in a class or class template $C$, called $S(N,C)$, consists of two component sets: the \term{declaration set}, a set of members named $N$; and the \term{subobject set}, @@ -1548,10 +1550,10 @@ in each direct non-dependent\iref{temp.dep.type} base class subobject $B_i$, and merge each such lookup set $S(N,B_i)$ in turn into $S(N,C)$. \begin{note} -If $T$ is incomplete, +If $C$ is incomplete, only base classes whose \grammarterm{base-specifier} appears before $P$ are considered. -If $T$ is an instantiated class, its base classes are not dependent. +If $C$ is an instantiated class, its base classes are not dependent. \end{note} \pnum @@ -1577,9 +1579,9 @@ \end{itemize} \pnum -The result of the search is the declaration set of $S(N,T)$. +The result of the search is the declaration set of $S(M,T)$. If it is an invalid set, the program is ill-formed. -If it differs from the result of a search in $T$ for $N$ +If it differs from the result of a search in $T$ for $M$ in a complete-class context\iref{class.mem} of $T$, the program is ill-formed, no diagnostic required. \begin{example} @@ -1602,7 +1604,7 @@ \end{example} \pnum -If $N$ is a non-dependent \grammarterm{conversion-function-id}, +If $M$ is a non-dependent \grammarterm{conversion-function-id}, conversion function templates that are members of $T$ are considered. For each such template $F$, the lookup set $S(t,T)$ is constructed, considering a function template declaration to have the name $t$ @@ -3329,7 +3331,7 @@ \pnum An operation that begins the lifetime of -an array of \tcode{char}, \tcode{unsigned char}, or \tcode{std::byte} +an array of \tcode{unsigned char} or \tcode{std::byte} implicitly creates objects within the region of storage occupied by the array. \begin{note} The array object provides storage for these objects. @@ -3407,8 +3409,11 @@ A \grammarterm{delete-expression}\iref{expr.delete} invokes the destructor prior to releasing the storage. \end{note} -In this case, the destructor is not implicitly invoked and any program that -depends on the side effects produced by the destructor has undefined behavior. +In this case, the destructor is not implicitly invoked. +\begin{note} +The correct behavior of a program often depends on +the destructor being invoked for each object of class type. +\end{note} \pnum Before the lifetime of an object has started but after the storage which diff --git a/source/classes.tex b/source/classes.tex index e13097d465..1f2ea99c5e 100644 --- a/source/classes.tex +++ b/source/classes.tex @@ -1944,7 +1944,7 @@ \end{example} \pnum -The implicitly-defined copy assignment operator for a +The implicitly-defined copy/move assignment operator for a union \tcode{X} copies the object representation\iref{term.object.representation} of \tcode{X}. If the source and destination of the assignment are not the same object, then for each object nested within\iref{intro.object} @@ -2095,7 +2095,7 @@ \pnum A defaulted destructor is a constexpr destructor -if it satisfies the requirements for a constexpr function\iref{dcl.constexpr}. +if it is constexpr-suitable\iref{dcl.constexpr}. \pnum Before a @@ -4270,6 +4270,19 @@ access control is applied to it, not to the declarations that replace it. For an overload set, access control is applied only to the function selected by overload resolution. +\begin{example} +\begin{codeblock} +struct S { + void f(int); +private: + void f(double); +}; + +void g(S* sp) { + sp->f(2); // OK, access control applied after overload resolution +} +\end{codeblock} +\end{example} \begin{note} Because access control applies to the declarations named, if access control is applied to a \grammarterm{typedef-name}, only the accessibility of the typedef or alias declaration itself is considered. @@ -6542,7 +6555,8 @@ \begin{itemize} \item -If \tcode{a <=> b} is usable\iref{class.compare.default}, +If \tcode{a <=> b} is usable\iref{class.compare.default} and +can be explicitly converted to \tcode{R} using \keyword{static_cast}, \tcode{static_cast(a <=> b)}. \item diff --git a/source/declarations.tex b/source/declarations.tex index a63c317a72..9eceedcfb8 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -205,7 +205,7 @@ \pnum If the \grammarterm{decl-specifier-seq} contains the \keyword{typedef} -specifier, the declaration is called a \defnx{typedef declaration}{declaration!typedef} +specifier, the declaration is a \defnx{typedef declaration}{declaration!typedef} and each \grammarterm{declarator-id} is declared to be a \grammarterm{typedef-name}, synonymous with its associated type\iref{dcl.typedef}. @@ -213,11 +213,20 @@ Such a \grammarterm{declarator-id} is an \grammarterm{identifier}\iref{class.conv.fct}. \end{note} -If the -\grammarterm{decl-specifier-seq} contains no \keyword{typedef} specifier, the -declaration is called a \defnx{function declaration}{declaration!function} if -the type associated with a \grammarterm{declarator-id} is a function type\iref{dcl.fct} and -an \defnx{object declaration}{declaration!object} otherwise. +Otherwise, if the type associated with a \grammarterm{declarator-id} +is a function type\iref{dcl.fct}, +the declaration is a \defnx{function declaration}{declaration!function}. +Otherwise, if the type associated with a \grammarterm{declarator-id} +is an object or reference type, the declaration is +an \defnx{object declaration}{declaration!object}. +Otherwise, the program is ill-formed. +\begin{example} +\begin{codeblock} +int f(), x; // OK, function declaration for \tcode{f} and object declaration for \tcode{x} +extern void g(), // OK, function declaration for \tcode{g} + y; // error: \tcode{void} is not an object type +\end{codeblock} +\end{example} \pnum \indextext{definition!declaration as}% @@ -787,16 +796,17 @@ \pnum \indextext{specifier!\idxcode{constexpr}!function}% \indextext{constexpr function}% -The definition of a constexpr function shall satisfy the following -requirements: +A function is \defn{constexpr-suitable} if: \begin{itemize} \item -it shall not be a coroutine\iref{dcl.fct.def.coroutine}; +it is not a coroutine\iref{dcl.fct.def.coroutine}, and \item if the function is a constructor or destructor, -its class shall not have any virtual base classes. +its class does not have any virtual base classes. \end{itemize} +Except for instantiated constexpr functions, +non-templated constexpr functions shall be constexpr-suitable. \begin{example} \begin{codeblock} @@ -830,16 +840,6 @@ \end{codeblock} \end{example} -\pnum -If the instantiated template specialization of a constexpr function -template -or member function of a class template -would fail to satisfy the requirements for a constexpr -function, -that specialization is still a constexpr function, -even though a call to such a function cannot appear in a constant -expression. - \pnum An invocation of a constexpr function in a given context produces the same result as @@ -885,7 +885,9 @@ In any \keyword{constexpr} variable declaration, the full-expression of the initialization shall be a constant expression\iref{expr.const}. -A \keyword{constexpr} variable shall have constant destruction. +A \keyword{constexpr} variable that is an object, +as well as any temporary to which a \keyword{constexpr} reference is bound, +shall have constant destruction. \begin{example} \begin{codeblock} struct pixel { @@ -909,10 +911,12 @@ \pnum If a variable declared with the \keyword{constinit} specifier has -dynamic initialization\iref{basic.start.dynamic}, the program is ill-formed. +dynamic initialization\iref{basic.start.dynamic}, the program is ill-formed, +even if the implementation would perform that initialization as +a static initialization\iref{basic.start.static}. \begin{note} The \keyword{constinit} specifier ensures that the variable -is initialized during static initialization\iref{basic.start.static}. +is initialized during static initialization. \end{note} \pnum @@ -1747,8 +1751,8 @@ \end{example} \pnum -Return type deduction for a templated entity -that is a function or function template with a placeholder in its +Return type deduction for a templated +function with a placeholder in its declared type occurs when the definition is instantiated even if the function body contains a \tcode{return} statement with a non-type-dependent operand. \begin{note} @@ -6252,7 +6256,7 @@ A function explicitly defaulted on its first declaration is implicitly inline\iref{dcl.inline}, and is implicitly constexpr\iref{dcl.constexpr} -if it satisfies the requirements for a constexpr function. +if it is constexpr-suitable. \pnum \begin{example} @@ -6968,6 +6972,8 @@ not omit the \grammarterm{enum-base}. The identifiers in an \grammarterm{enumerator-list} are declared as constants, and can appear wherever constants are required. +The same identifier shall not appear as +the name of multiple enumerators in an \grammarterm{enumerator-list}. \indextext{enumerator!value of}% An \grammarterm{enumerator-definition} with \tcode{=} gives the associated \grammarterm{enumerator} the value indicated by the @@ -8251,7 +8257,7 @@ in determining the language linkage of class members, friend functions with a trailing \grammarterm{requires-clause}, and the -function type of class member functions. +function type of non-static class member functions. \begin{example} \begin{codeblock} extern "C" typedef void FUNC_c(); @@ -8505,6 +8511,17 @@ the rules specifying to which entity or statement the attribute can apply or the syntax rules for the attribute's \grammarterm{attribute-argument-clause}, if any. \end{note} +\begin{note} +The \grammarterm{attribute}{s} specified in \ref{dcl.attr} +have optional semantics: +given a well-formed program, +removing all instances of any one of those \grammarterm{attribute}{s} +results in a program whose set of possible executions\iref{intro.abstract} +for a given input is +a subset of those of the original program for the same input, +absent implementation-defined guarantees +with respect to that \grammarterm{attribute}. +\end{note} An \grammarterm{attribute-token} is reserved for future standardization if \begin{itemize} \item it is not an \grammarterm{attribute-scoped-token} and diff --git a/source/expressions.tex b/source/expressions.tex index 67edaeebf1..24ca008a05 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -1142,38 +1142,34 @@ \item Otherwise, the expression is ill-formed. \end{itemize} -\item Otherwise, the integral promotions\iref{conv.prom} are -performed on both operands. +\item Otherwise, each operand is converted to a common type \tcode{C}. +The integral promotion rules\iref{conv.prom} are used +to determine a type \tcode{T1} and type \tcode{T2} for each operand. \begin{footnote} As a consequence, operands of type \keyword{bool}, \keyword{char8_t}, \keyword{char16_t}, \keyword{char32_t}, \keyword{wchar_t}, or of enumeration type are converted to some integral type. \end{footnote} -Then the following rules are applied to the promoted operands: +Then the following rules are applied to determine \tcode{C}: \begin{itemize} -\item If both operands have the same type, no further conversion is -needed. +\item If \tcode{T1} and \tcode{T2} are the same type, \tcode{C} is that type. -\item Otherwise, if both operands have signed integer types or both have -unsigned integer types, the operand with the type of lesser integer -conversion rank is converted to the type of the operand with -greater rank. +\item Otherwise, if \tcode{T1} and \tcode{T2} are both signed integer types or +are both unsigned integer types, +\tcode{C} is the type with greater rank. -\item Otherwise, if the operand that has unsigned integer type has rank -greater than or equal to the rank of the type of the other operand, the -operand with signed integer type is converted to the type of the -operand with unsigned integer type. - -\item Otherwise, if the type of the operand with signed integer type can -represent all of the values of the type of the operand with unsigned -integer type, the operand with unsigned integer type is converted -to the type of the operand with signed integer type. - -\item Otherwise, both operands are converted to the unsigned -integer type corresponding to the type of the operand with signed -integer type. +\item Otherwise, let \tcode{U} be the unsigned integer type and +\tcode{S} be the signed integer type. +\begin{itemize} +\item If \tcode{U} has rank greater than or equal to the rank of \tcode{S}, +\tcode{C} is \tcode{U}. +\item Otherwise, if \tcode{S} can represent all of the values of \tcode{U}, +\tcode{C} is \tcode{S}. +\item Otherwise, +\tcode{C} is the unsigned integer type corresponding to \tcode{S}. +\end{itemize} \end{itemize} \end{itemize} @@ -1965,7 +1961,7 @@ the corresponding \grammarterm{lambda-expression}{'s} \grammarterm{parameter-declaration-clause} is followed by \keyword{constexpr} or \keyword{consteval}, or -it satisfies the requirements for a constexpr function\iref{dcl.constexpr}. +it is constexpr-suitable\iref{dcl.constexpr}. It is an immediate function\iref{dcl.constexpr} if the corresponding \grammarterm{lambda-expression}{'s} \grammarterm{parameter-declaration-clause} is followed by \keyword{consteval}. @@ -3055,18 +3051,6 @@ \end{codeblock} \tcode{D} is satisfied if \tcode{sizeof(decltype (+t)) == 1}\iref{temp.constr.atomic}. \end{example} - -\pnum -A local parameter shall only appear as an unevaluated operand\iref{term.unevaluated.operand} -within the \grammarterm{constraint-expression}. -\begin{example} -\begin{codeblock} -template concept C = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // error: evaluation of a constraint variable -}; -\end{codeblock} -\end{example} \indextext{expression!requires|)} \indextext{expression!primary|)} @@ -6555,6 +6539,11 @@ \tcode{q<=p}, and \tcode{q=p}, and \tcode{q>p} all yield \keyword{false}. Otherwise, the result of each of the operators is unspecified. +\begin{note} +A relational operator applied +to unequal function pointers or to unequal pointers to \tcode{void} +yields an unspecified result. +\end{note} \pnum If both operands (after conversions) are of arithmetic or enumeration type, each @@ -7390,8 +7379,7 @@ \item an invocation of an instantiated constexpr function -that fails to satisfy the requirements -for a constexpr function; +that is not constexpr-suitable; \item an invocation of a virtual function\iref{class.virtual} @@ -7628,6 +7616,15 @@ to storage allocated with \tcode{std::allocator} or to an object whose lifetime began within the evaluation of $E$. +\pnum +For the purposes of determining whether $E$ is a core constant expression, +the evaluation of a call to +a trivial copy/move constructor or copy/move assignment operator of a union +is considered to copy/move the active member of the union, if any. +\begin{note} +The copy/move of the active member is trivial. +\end{note} + \pnum During the evaluation of an expression $E$ as a core constant expression, all \grammarterm{id-expression}s and uses of \tcode{*\keyword{this}} @@ -7785,6 +7782,11 @@ if the value is an object of class type, each non-static data member of reference type refers to an entity that is a permitted result of a constant expression, + + \item + if the value is an object of scalar type, + it does not have an indeterminate value\iref{basic.indet}, + \item if the value is of pointer type, it contains the address of an object with static storage duration, diff --git a/source/intro.tex b/source/intro.tex index e14bda23af..56ab3039f2 100644 --- a/source/intro.tex +++ b/source/intro.tex @@ -600,7 +600,7 @@ parameter-type-list, enclosing namespace, return type, -\grammarterm{template-head}, +signature of the \grammarterm{template-head}, and trailing \grammarterm{requires-clause} (if any) @@ -611,7 +611,7 @@ parameter-type-list, return type, enclosing class, -\grammarterm{template-head}, +signature of the \grammarterm{template-head}, and trailing \grammarterm{requires-clause} (if any) @@ -640,7 +640,7 @@ \cv-qualifiers (if any), \grammarterm{ref-qualifier} (if any), return type (if any), -\grammarterm{template-head}, +signature of the \grammarterm{template-head}, and trailing \grammarterm{requires-clause} (if any) @@ -649,6 +649,14 @@ \defncontext{class member function template specialization} signature of the member function template of which it is a specialization and its template arguments (whether explicitly specified or deduced) +\indexdefn{signature}% +\definition{signature}{defns.signature.template.head} +\defncontext{\grammarterm{template-head}} +template parameter list, +excluding template parameter names and default arguments, +and +\grammarterm{requires-clause} (if any) + \definition{stable algorithm}{defns.stable} \defncontext{library} \indexdefn{algorithm!stable}% diff --git a/source/modules.tex b/source/modules.tex index 0a65f8c069..f38503d39e 100644 --- a/source/modules.tex +++ b/source/modules.tex @@ -512,6 +512,13 @@ \end{footnote} These rules can in turn lead to the importation of yet more translation units. +\begin{note} +Such indirect importation does not make macros available, +because a translation unit is +a sequence of tokens in translation phase 7\iref{lex.phases}. +Macros can be made available by directly importing header units +as described in \ref{cpp.import}. +\end{note} \pnum A module implementation unit shall not be exported. diff --git a/source/overloading.tex b/source/overloading.tex index cf0568fbb0..d09474051f 100644 --- a/source/overloading.tex +++ b/source/overloading.tex @@ -723,6 +723,7 @@ operands can be converted according to \ref{over.best.ics}, and \item do not have the same parameter-type-list as any non-member candidate +or rewritten non-member candidate that is not a function template specialization. \end{itemize} @@ -1240,8 +1241,12 @@ \begin{itemize} \item brace elision is not considered for any aggregate element -that has a dependent non-array type or -an array type with a value-dependent bound, and +that has +\begin{itemize} +\item a dependent non-array type, +\item an array type with a value-dependent bound, or +\item an array type with a dependent array element type and $x_i$ is a string literal; and +\end{itemize} \item each non-trailing aggregate element that is a pack expansion is assumed to correspond to no elements of the initializer list, and @@ -1257,9 +1262,14 @@ \begin{itemize} \item if $e_i$ is of array type and -$x_i$ is a \grammarterm{braced-init-list} or \grammarterm{string-literal}, +$x_i$ is a \grammarterm{braced-init-list}, $\tcode{T}_i$ is an rvalue reference to the declared type of $e_i$, and \item +if $e_i$ is of array type and +$x_i$ is a \grammarterm{string-literal}, +$\tcode{T}_i$ is an lvalue reference to +the const-qualified declared type of $e_i$, and +\item otherwise, $\tcode{T}_i$ is the declared type of $e_i$, \end{itemize} except that additional parameter packs of the form $\tcode{P}_j \tcode{...}$ @@ -1329,6 +1339,23 @@ } G g(true, 'a', 1); // OK, deduces \tcode{G} + +template +struct H { + T array[N]; +}; +template +struct I { + volatile T array[N]; +}; +template +struct J { + unsigned char array[N]; +}; + +H h = { "abc" }; // OK, deduces \tcode{H} (not \tcode{T = const char}) +I i = { "def" }; // OK, deduces \tcode{I} +J j = { "ghi" }; // error: cannot bind reference to array of \tcode{unsigned char} to array of \tcode{char} in deduction \end{codeblock} \end{example} @@ -1351,6 +1378,8 @@ according to the process in \ref{temp.deduct.type} with the exception that deduction does not fail if not all template arguments are deduced. +If deduction fails for another reason, +proceed with an empty set of deduced template arguments. Let \tcode{g} denote the result of substituting these deductions into \tcode{f}. If substitution succeeds, diff --git a/source/preprocessor.tex b/source/preprocessor.tex index d01c69babf..d7b1201e6e 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -929,6 +929,18 @@ int a = Y; // OK, active macro definitions \#2 and \#4 are valid redefinitions int c = Z; // error: active macro definitions \#3 and \#5 are not valid redefinitions of \tcode{Z} \end{codeblocktu} + +\begin{codeblocktu}{Module unit \tcode{f}} +export module f; +export import "a.h"; + +int a = Y; // OK +\end{codeblocktu} + +\begin{codeblocktu}{Translation unit \tcode{\#1}} +import f; +int x = Y; // error: \tcode{Y} is neither a defined macro nor a declared name +\end{codeblocktu} \end{example} \indextext{macro!import|)} diff --git a/source/templates.tex b/source/templates.tex index c726e771ff..d5d79e8b76 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -172,6 +172,13 @@ templated entity is a templated entity. \end{note} +A \defnadj{templated}{function} is +a function template or a function that is templated. +A \defnadj{templated}{class} is +a class template or a class that is templated. +A \defnadj{templated}{variable} is +a variable template or a variable that is templated. + \pnum A \grammarterm{template-declaration} is written in terms of its template parameters. @@ -5991,7 +5998,7 @@ causes specializations in the default member initializer to be instantiated. \pnum -If a function template +If a templated function \tcode{f} is called in a way that requires a default argument to be used, the dependent names are looked up, the semantics constraints are checked, @@ -6604,7 +6611,7 @@ \pnum Whether an explicit specialization of a function or variable template -is inline, constexpr, or an immediate function +is inline, constexpr, constinit, or consteval is determined by the explicit specialization and is independent of those properties of the template. Similarly,