<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Aug 14, 2024, at 8:13 AM, Fred J. Tydeman <tydeman@tybor.com> wrote:</div><br class="Apple-interchange-newline"><div><div>..................Begin Forwarded Message..................<br><br>From: Aaron Ballman <aaron@aaronballman.com><br>To: Joseph Myers <josmyers@redhat.com><br>Cc: wg14 <sc22wg14@open-std.org><br>Date: Thu, 1 Aug 2024 13:33:18 -0400<br>Subject: [SC22WG14.26243] constexpr initialization seemingly can contain UB?<br><br>On Thu, Aug 1, 2024 at 12:59PM Joseph Myers <josmyers@redhat.com> wrote:<br><blockquote type="cite"><br>On Thu, 1 Aug 2024, Aaron Ballman wrote:<br><br><blockquote type="cite">Consider the following example:<br><br>constexpr float f = 1.0f / 0.0f<br><br>According to my reading of the C23 standard, this is conforming and<br>should result in `f` holding infinity, presuming that the target<br>supports infinities in their floating-point representation (see<br>5.2.5.3.3 for what is "in the range of representable values")<br><br>However, 6.5.6p6 makes this undefined behavior explicitly:<br>The result of the / operator is the quotient from the division of the<br>first operand by the second; the result of the % operator is the<br>remainder. In both operations, if the value of the second operand is<br>zero, the behavior is undefined.<br></blockquote><br>It was previously stated in response to DR#442 that "WG14 treats normative<br>annexes such as Annex F as if they were linear extensions of the standard<br>itself. When Annex F is requested via definition of __STDC_IEC_559__ then<br>6.5#5 is superseded and floating point exceptions become well defined.".<br>I think that applies to the specification of the division operator just as<br>to the general statement about exceptional conditions - the rules for<br>translation-time evaluation thus apply, as long as Annex F is implemented,<br>to give the result of evaluating that expression in the default rounding<br>mode with default exception handling and exceptions discarded.  See the<br>example in F.8.5.<br></blockquote><br>Agreed, but Annex F doesn't save us here -- there are targets for<br>which my implementation cannot conform to Annex F for <reasons>, and<br>we don't claim conformance on any target currently by defining the<br>__STDC_IEC_559__ macro.<br></div></div></blockquote><div><br></div><div>3.5.3 (undefined behavior) #2 says:</div><div><br></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div>Note 1 to entry: Possible undefined behavior ranges from ignoring the situation completely with unpredictable</div></div></div><div><div><div>results, to <span style="background-color: rgb(255, 251, 0);">behaving during translation or program execution in a documented manner characteristic of the</span></div></div></div><div><div><div><span style="background-color: rgb(255, 251, 0);">environment (with or without the issuance of a diagnostic message)</span>, ...</div></div></div></blockquote><div><br></div><div>This would seem to mean an implementation that does not declare support for Annex F but that does document its support for infinity could set f to +infinity without issuing a diagnostic message. </div><div><br></div><div>Does this help?</div><div><br></div><div>- Jim Thomas</div><div><br><blockquote type="cite"><div><div><br>~Aaron<br><br><blockquote type="cite"><br>--<br>Joseph S. Myers<br>josmyers@redhat.com<br><br></blockquote><br>...................End Forwarded Message..................<br><br><br>---<br>Fred J. Tydeman        Tydeman Consulting<br>tydeman@tybor.com      Testing, numerics, programming<br>+1 (702) 608-6093      Vice-chair of INCITS/C (ANSI "C")<br>Sample C17+FPCE tests: http://www.tybor.com<br>Savers sleep well, investors eat well, spenders work forever.<br><br>_______________________________________________<br>Cfp-interest mailing list<br>Cfp-interest@oakapple.net<br>http://mailman.oakapple.net/mailman/listinfo/cfp-interest<br></div></div></blockquote></div><br></body></html>