diff --git a/source/declarations.tex b/source/declarations.tex index 9eceedcfb8..84e70417de 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -257,14 +257,32 @@ is contextually converted to \keyword{bool} and the converted expression shall be a constant expression\iref{expr.const}. If the value of the expression when -so converted is \tcode{true}, the declaration has no -effect. Otherwise, the program is ill-formed, and the resulting +so converted is \tcode{true} +or the expression is evaluated in the context of a template definition, +the declaration has no +effect. Otherwise, +the \grammarterm{static_assert-declaration} fails, +the program is ill-formed, and the resulting diagnostic message\iref{intro.compliance} should include the text of the \grammarterm{string-literal}, if one is supplied. \begin{example} \begin{codeblock} static_assert(sizeof(int) == sizeof(void*), "wrong pointer size"); static_assert(sizeof(int[2])); // OK, narrowing allowed + +template +void f(T t) { + if constexpr (sizeof(T) == sizeof(int)) { + use(t); + } else { + static_assert(false, "must be int-sized"); + } +} + +void g(char c) { + f(0); // OK + f(c); // error on implementations where \tcode{sizeof(int) > 1}: must be \tcode{int}-sized +} \end{codeblock} \end{example} diff --git a/source/intro.tex b/source/intro.tex index 56ab3039f2..d8c059d829 100644 --- a/source/intro.tex +++ b/source/intro.tex @@ -800,16 +800,16 @@ \end{footnote} that program. \item +\indextext{behavior!undefined}% +If a program contains a violation of a rule for which no diagnostic is required, +this document places no requirement on implementations +with respect to that program. +\item \indextext{message!diagnostic}% -If a program contains a violation of any diagnosable rule or an occurrence +Otherwise, if a program contains a violation of any diagnosable rule or an occurrence of a construct described in this document as ``conditionally-supported'' when the implementation does not support that construct, a conforming implementation shall issue at least one diagnostic message. -\item -\indextext{behavior!undefined}% -If a program contains a violation of a rule for which no diagnostic -is required, this document places no requirement on -implementations with respect to that program. \end{itemize} \begin{note} During template argument deduction and substitution, @@ -817,6 +817,20 @@ are treated differently; see~\ref{temp.deduct}. \end{note} +Furthermore, a conforming implementation +\begin{itemize} +\item +shall not accept a preprocessing translation unit containing +a \tcode{\#error} preprocessing directive\iref{cpp.error}, +\item +shall issue at least one diagnostic message for +each \tcode{\#warning} or \tcode{\#error} preprocessing directive +not following a \tcode{\#error} preprocessing directive in +a preprocessing translation unit, and +\item +shall not accept a translation unit with +a \grammarterm{static_assert-declaration} that fails\iref{dcl.pre}. +\end{itemize} \pnum \indextext{conformance requirements!library|(}% diff --git a/source/lex.tex b/source/lex.tex index c18e288238..79922d5e41 100644 --- a/source/lex.tex +++ b/source/lex.tex @@ -33,7 +33,7 @@ and source files included\iref{cpp.include} via the preprocessing directive \tcode{\#include}, less any source lines skipped by any of the conditional inclusion\iref{cpp.cond} preprocessing directives, is -called a \defn{translation unit}. +called a \defnadj{preprocessing}{translation unit}. \begin{note} A \Cpp{} program need not all be translated at the same time. \end{note} @@ -168,8 +168,10 @@ \item Whitespace characters separating tokens are no longer significant. Each preprocessing token is converted into a -token\iref{lex.token}. The resulting tokens are syntactically and -semantically analyzed and translated as a translation unit. +token\iref{lex.token}. The resulting tokens +constitute a \defn{translation unit} and +are syntactically and +semantically analyzed and translated. \begin{note} The process of analyzing and translating the tokens can occasionally result in one token being replaced by a sequence of other diff --git a/source/templates.tex b/source/templates.tex index d5d79e8b76..c7c282e8d5 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -4444,7 +4444,9 @@ The program is ill-formed, no diagnostic required, if: \begin{itemize} \item -no valid specialization can be generated for a template +no valid specialization, +ignoring \grammarterm{static_assert-declaration}{s} that fail, +can be generated for a template or a substatement of a constexpr if statement\iref{stmt.if} within a template and the template is not instantiated, or \item