<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2518</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="2518"></A><H4>2518.
  
Conformance requirements and <TT>#error</TT>/<TT>#warning</TT>
</H4>
<B>Section: </B>4.1.1&#160; [<A href="https://wg21.link/intro.compliance.general">intro.compliance.general</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++23
 &#160;&#160;&#160;

 <B>Submitter: </B>CWG
 &#160;&#160;&#160;

 <B>Date: </B>2022-01-13
  &#160;&#160;&#160;
  <B>Liaison: </B>(EWG)<BR>


<P>[Accepted as a DR at the February, 2023 meeting.]</P>

<P>According to 4.1.1 [<A href="https://wg21.link/intro.compliance.general#2.2">intro.compliance.general</A>] bullet 2.2,</P>

<BLOCKQUOTE>

a conforming implementation shall issue at least one diagnostic message

</BLOCKQUOTE>

<P>for an ill-formed program that is not &#8220;no
diagnostic required.&#8221; The relationship between this
diagnostic message and the ones required by
the <TT>#error</TT> and <TT>#warning</TT> preprocessor
directives is not clear. For example, is an implementation
required to emit multiple diagnostics if
multiple <TT>#error</TT> directives are encountered, even
though conformance requires only one?  Could an
implementation count the diagnostic emitted by
<TT>#warning</TT> as satisfying the requirement for an
ill-formed program?</P>

<P>See also <A HREF="745.html">issue 745</A>.</P>

<P><U>Suggested resolution [SUPERSEDED]:</U></P>

<P>Add a new paragraph after 4.1.1 [<A href="https://wg21.link/intro.compliance.general#2">intro.compliance.general</A>] paragraph 2 as follows:</P>

<BLOCKQUOTE>

Although this document states only requirements on C++
implementations, those requirements are often easier to understand if
they are phrased as requirements on programs, parts of programs, or
execution of programs. Such requirements have the following meaning:

<UL>
<LI>
If a program contains no violations of the rules in Clause
Clause 5 [<A href="https://wg21.link/lex">lex</A>] through Clause Clause 32 [<A href="https://wg21.link/thread">thread</A>] and
Annex D, a conforming implementation shall, within its resource limits
as described in Annex B, accept and correctly execute
[ <I>Footnote:</I> ... ] that program.</LI>

<LI>
If a program contains a violation of any diagnosable rule or an
occurrence of a construct described in this document as
&#8220;conditionally-supported&#8221; when the implementation does not
support that construct, a conforming implementation shall issue at
least one diagnostic message.
</LI>

<LI>
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.
</LI>

</UL>

<P>[<I>Note</I>: ... &#8212; <I>end note</I>]</P>

<P><INS>Furthermore, a conforming implementation</INS></P>
<UL>
<LI>
<INS>shall not accept a translation unit containing a <TT>#error</TT>
preprocessing directive (15.9 [<A href="https://wg21.link/cpp.error">cpp.error</A>]) unless it is part
of a group skipped by conditional inclusion
(15.2 [<A href="https://wg21.link/cpp.cond">cpp.cond</A>]) and</INS>
</LI>

<LI>
<INS>shall issue at least one diagnostic message for
each <TT>#warning</TT> or <TT>#error</TT> preprocessing directive not
following a <TT>#error</TT> preprocessing directive,
ignoring <TT>#warning</TT> and <TT>#error</TT> preprocessing
directives appearing in groups skipped by conditional inclusion.</INS>
</LI>

</UL>

<P>For classes and class templates, ...</P>

</BLOCKQUOTE>

<P><B>Notes from the November, 2022 meeting</B></P>

<P>EWG review solicited via
<A HREF="https://github.com/cplusplus/papers/issues/1366">cplusplus/papers#1366</A>.</P>

<P><B>EWG 2023-02-06</B></P>

<P>EWG agreed with the suggested resolution, but resolved to amend it
to treat <TT>static_assert</TT> similarly.</P>

<P><B>Proposed resolution (February, 2023) [SUPERSEDED]:</B></P>

<OL>

<LI>
<P>Change and add a new paragraph after 4.1.1 [<A href="https://wg21.link/intro.compliance.general#2">intro.compliance.general</A>] paragraph 2 as follows:</P>

<BLOCKQUOTE>

Although this document states only requirements on C++
implementations, those requirements are often easier to understand if
they are phrased as requirements on programs, parts of programs, or
execution of programs. Such requirements have the following meaning:

<UL>
<LI>
If a program contains no violations of the rules in Clause
Clause 5 [<A href="https://wg21.link/lex">lex</A>] through Clause Clause 32 [<A href="https://wg21.link/thread">thread</A>] and
Annex D, a conforming implementation shall, within its resource limits
as described in Annex B, accept and correctly execute
[ <I>Footnote:</I> ... ] that program.</LI>

<LI class="ins">
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.
</LI>

<LI>
<INS>Otherwise, if</INS> <DEL>If</DEL> a program contains a violation of any diagnosable rule or an
occurrence of a construct described in this document as
&#8220;conditionally-supported&#8221; when the implementation does not
support that construct, a conforming implementation shall issue at
least one diagnostic message.
</LI>

<LI>
<DEL>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.</DEL>
[<I>Note</I>: During template argument deduction and substitution, certain constructs that in other contexts require a diagnostic are treated differently; see [temp.deduct] &#8212; <I>end note</I>]
</LI>

<P><INS>Furthermore, a conforming implementation</INS></P>
<UL class="ins">
<LI>
shall not accept a preprocessing translation unit containing a <TT>#error</TT>
preprocessing directive (15.9 [<A href="https://wg21.link/cpp.error">cpp.error</A>]),
</LI>

<LI>
shall issue at least one diagnostic message for each <TT>#warning</TT>
or <TT>#error</TT> preprocessing directive not following
a <TT>#error</TT> preprocessing directive in a preprocessing
translation unit, and
</LI>

<LI>
shall not accept a translation unit with
a failed <I>static_assert-declaration</I> (9.1 [<A href="https://wg21.link/dcl.pre">dcl.pre</A>])
<INS>outside an uninstantiated template</INS>.
</LI>

</UL>

</UL>

<P>For classes and class templates, ...</P>

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 5.1 [<A href="https://wg21.link/lex.separate#1">lex.separate</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

The text of the program is kept in units called source files in this
document. A source file together with all the headers
(16.4.2.3 [<A href="https://wg21.link/headers">headers</A>]) and source files included
(15.3 [<A href="https://wg21.link/cpp.include">cpp.include</A>]) via the preprocessing directive #include,
less any source lines skipped by any of the conditional inclusion
(15.2 [<A href="https://wg21.link/cpp.cond">cpp.cond</A>]) preprocessing directives, is called a
<I><INS>preprocessing</INS> translation unit</I>.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 5.2 [<A href="https://wg21.link/lex.phases#7">lex.phases</A>] paragraph 7 as follows:</P>


<BLOCKQUOTE>

... The resulting tokens <INS>constitute a <I>translation unit</I>
and</INS> are syntactically and semantically analyzed and
translated <DEL>as a translation unit</DEL>.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 9.1 [<A href="https://wg21.link/dcl.pre#10">dcl.pre</A>] paragraph 10 as follows:</P>

<BLOCKQUOTE>

In a <I><TT>static_assert</TT>-declaration</I>, the
constant-expression is contextually converted to bool and the
converted expression shall be a constant expression
(7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]). If the value of the expression when so
converted is true, the declaration has no
effect. Otherwise, <INS>the <I><TT>static_assert</TT>-declaration</I> has
<I>failed</I>,</INS> the program is ill-formed, and the resulting
diagnostic message (4.1 [<A href="https://wg21.link/intro.compliance">intro.compliance</A>]) should include the text
of the string-literal, if one is supplied.

</BLOCKQUOTE>
</LI>

</OL>

<P><B>CWG 2023-02-10</B></P>

<P>CWG decided to fold P2593R1 (static_assert(false)) into the
proposed resolution.</P>

<P><B>Proposed resolution (approved by CWG 2023-02-10):</B></P>

<OL>

<LI>
<P>Change and add a new paragraph after 4.1.1 [<A href="https://wg21.link/intro.compliance.general#2">intro.compliance.general</A>] paragraph 2 as follows:</P>

<BLOCKQUOTE>

Although this document states only requirements on C++
implementations, those requirements are often easier to understand if
they are phrased as requirements on programs, parts of programs, or
execution of programs. Such requirements have the following meaning:

<UL>
<LI>
If a program contains no violations of the rules in Clause
Clause 5 [<A href="https://wg21.link/lex">lex</A>] through Clause Clause 32 [<A href="https://wg21.link/thread">thread</A>] and
Annex D, a conforming implementation shall, within its resource limits
as described in Annex B, accept and correctly execute
[ <I>Footnote:</I> ... ] that program.</LI>

<LI class="ins">
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.
</LI>

<LI>
<INS>Otherwise, if</INS> <DEL>If</DEL> a program contains a violation of any diagnosable rule or an
occurrence of a construct described in this document as
&#8220;conditionally-supported&#8221; when the implementation does not
support that construct, a conforming implementation shall issue at
least one diagnostic message.
</LI>

<LI>
<DEL>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.</DEL>
[<I>Note</I>: During template argument deduction and substitution, certain constructs that in other contexts require a diagnostic are treated differently; see [temp.deduct] &#8212; <I>end note</I>]
</LI>

<P><INS>Furthermore, a conforming implementation</INS></P>
<UL class="ins">
<LI>
shall not accept a preprocessing translation unit containing a <TT>#error</TT>
preprocessing directive (15.9 [<A href="https://wg21.link/cpp.error">cpp.error</A>]),
</LI>

<LI>
shall issue at least one diagnostic message for each <TT>#warning</TT>
or <TT>#error</TT> preprocessing directive not following
a <TT>#error</TT> preprocessing directive in a preprocessing
translation unit, and
</LI>

<LI>
shall not accept a translation unit with
a <I>static_assert-declaration</I> that fails (9.1 [<A href="https://wg21.link/dcl.pre">dcl.pre</A>]).
</LI>

</UL>

</UL>

<P>For classes and class templates, ...</P>

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 5.1 [<A href="https://wg21.link/lex.separate#1">lex.separate</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

The text of the program is kept in units called source files in this
document. A source file together with all the headers
(16.4.2.3 [<A href="https://wg21.link/headers">headers</A>]) and source files included
(15.3 [<A href="https://wg21.link/cpp.include">cpp.include</A>]) via the preprocessing directive #include,
less any source lines skipped by any of the conditional inclusion
(15.2 [<A href="https://wg21.link/cpp.cond">cpp.cond</A>]) preprocessing directives, is called a
<I><INS>preprocessing</INS> translation unit</I>.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 5.2 [<A href="https://wg21.link/lex.phases#7">lex.phases</A>] paragraph 7 as follows:</P>


<BLOCKQUOTE>

... The resulting tokens <INS>constitute a <I>translation unit</I>
and</INS> are syntactically and semantically analyzed and
translated <DEL>as a translation unit</DEL>.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 9.1 [<A href="https://wg21.link/dcl.pre#10">dcl.pre</A>] paragraph 10 as follows:</P>

<BLOCKQUOTE>

In a <I><TT>static_assert</TT>-declaration</I>, the
constant-expression is contextually converted to bool and the
converted expression shall be a constant expression
(7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]). If the value of the expression when so
converted is true <INS>or the expression is evaluated in the context
of a template definition</INS>, the declaration has no
effect. Otherwise, <INS>the <I><TT>static_assert</TT>-declaration</I>
<I>fails</I>,</INS> the program is ill-formed, and the resulting
diagnostic message (4.1 [<A href="https://wg21.link/intro.compliance">intro.compliance</A>]) should include the text
of the string-literal, if one is supplied.

[ Example:

<PRE>
  static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
  static_assert(sizeof(int[2]));   //<SPAN CLASS="cmnt"> OK, narrowing allowed</SPAN>
<DIV class="ins">
  template &lt;class T&gt;
  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); //<SPAN CLASS="cmnt"> OK</SPAN>
    f(c); //<SPAN CLASS="cmnt"> error: must be int-sized</SPAN>
  }
  </DIV>
</PRE>
-- end example ]
</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 13.8 [<A href="https://wg21.link/temp.res#6">temp.res</A>] paragraph 6 as follows:</P>


<BLOCKQUOTE>

... The program is ill-formed, no diagnostic required, if:
<UL>
<LI>
no valid specialization<INS>, ignoring
<I><TT>static_assert</TT>-declarations</I> that fail,</INS> can be
generated for a template or a substatement of a constexpr if statement
(8.5.2 [<A href="https://wg21.link/stmt.if">stmt.if</A>]) within a template and the template is not
instantiated, or
</LI>

<LI>...</LI>

</UL>

</BLOCKQUOTE>
</LI>

</OL>

<BR><BR>
</BODY>
</HTML>
