Skip to content

Commit 7452792

Browse files
authored
Merge 2023-02 CWG Motion 3
P2796R0 Core Language Working Group "ready" issues for the February, 2023 meeting; issue 2518
2 parents d87a206 + b334df6 commit 7452792

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

source/declarations.tex

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,32 @@
257257
is contextually converted to \keyword{bool} and
258258
the converted expression shall be a constant expression\iref{expr.const}.
259259
If the value of the expression when
260-
so converted is \tcode{true}, the declaration has no
261-
effect. Otherwise, the program is ill-formed, and the resulting
260+
so converted is \tcode{true}
261+
or the expression is evaluated in the context of a template definition,
262+
the declaration has no
263+
effect. Otherwise,
264+
the \grammarterm{static_assert-declaration} fails,
265+
the program is ill-formed, and the resulting
262266
diagnostic message\iref{intro.compliance} should include the text of
263267
the \grammarterm{string-literal}, if one is supplied.
264268
\begin{example}
265269
\begin{codeblock}
266270
static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
267271
static_assert(sizeof(int[2])); // OK, narrowing allowed
272+
273+
template <class T>
274+
void f(T t) {
275+
if constexpr (sizeof(T) == sizeof(int)) {
276+
use(t);
277+
} else {
278+
static_assert(false, "must be int-sized");
279+
}
280+
}
281+
282+
void g(char c) {
283+
f(0); // OK
284+
f(c); // error on implementations where \tcode{sizeof(int) > 1}: must be \tcode{int}-sized
285+
}
268286
\end{codeblock}
269287
\end{example}
270288

source/intro.tex

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -800,23 +800,37 @@
800800
\end{footnote}
801801
that program.
802802
\item
803+
\indextext{behavior!undefined}%
804+
If a program contains a violation of a rule for which no diagnostic is required,
805+
this document places no requirement on implementations
806+
with respect to that program.
807+
\item
803808
\indextext{message!diagnostic}%
804-
If a program contains a violation of any diagnosable rule or an occurrence
809+
Otherwise, if a program contains a violation of any diagnosable rule or an occurrence
805810
of a construct described in this document as ``conditionally-supported'' when
806811
the implementation does not support that construct, a conforming implementation
807812
shall issue at least one diagnostic message.
808-
\item
809-
\indextext{behavior!undefined}%
810-
If a program contains a violation of a rule for which no diagnostic
811-
is required, this document places no requirement on
812-
implementations with respect to that program.
813813
\end{itemize}
814814
\begin{note}
815815
During template argument deduction and substitution,
816816
certain constructs that in other contexts require a diagnostic
817817
are treated differently;
818818
see~\ref{temp.deduct}.
819819
\end{note}
820+
Furthermore, a conforming implementation
821+
\begin{itemize}
822+
\item
823+
shall not accept a preprocessing translation unit containing
824+
a \tcode{\#error} preprocessing directive\iref{cpp.error},
825+
\item
826+
shall issue at least one diagnostic message for
827+
each \tcode{\#warning} or \tcode{\#error} preprocessing directive
828+
not following a \tcode{\#error} preprocessing directive in
829+
a preprocessing translation unit, and
830+
\item
831+
shall not accept a translation unit with
832+
a \grammarterm{static_assert-declaration} that fails\iref{dcl.pre}.
833+
\end{itemize}
820834

821835
\pnum
822836
\indextext{conformance requirements!library|(}%

source/lex.tex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
and source files included\iref{cpp.include} via the preprocessing
3434
directive \tcode{\#include}, less any source lines skipped by any of the
3535
conditional inclusion\iref{cpp.cond} preprocessing directives, is
36-
called a \defn{translation unit}.
36+
called a \defnadj{preprocessing}{translation unit}.
3737
\begin{note}
3838
A \Cpp{} program need not all be translated at the same time.
3939
\end{note}
@@ -168,8 +168,10 @@
168168

169169
\item Whitespace characters separating tokens are no longer
170170
significant. Each preprocessing token is converted into a
171-
token\iref{lex.token}. The resulting tokens are syntactically and
172-
semantically analyzed and translated as a translation unit.
171+
token\iref{lex.token}. The resulting tokens
172+
constitute a \defn{translation unit} and
173+
are syntactically and
174+
semantically analyzed and translated.
173175
\begin{note}
174176
The process of analyzing and translating the tokens can occasionally
175177
result in one token being replaced by a sequence of other

source/templates.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4444,7 +4444,9 @@
44444444
The program is ill-formed, no diagnostic required, if:
44454445
\begin{itemize}
44464446
\item
4447-
no valid specialization can be generated for a template
4447+
no valid specialization,
4448+
ignoring \grammarterm{static_assert-declaration}{s} that fail,
4449+
can be generated for a template
44484450
or a substatement of a constexpr if statement\iref{stmt.if} within a template
44494451
and the template is not instantiated, or
44504452
\item

0 commit comments

Comments
 (0)