Skip to content

[CWG 3] P2796R0 CWG2518 Conformance requirements and #error/#warning #6120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
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}

Expand Down
26 changes: 20 additions & 6 deletions source/intro.tex
Original file line number Diff line number Diff line change
Expand Up @@ -800,23 +800,37 @@
\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,
certain constructs that in other contexts require a diagnostic
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|(}%
Expand Down
8 changes: 5 additions & 3 deletions source/lex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion source/templates.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down