<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:dblaikie@gmail.com" title="David Blaikie <dblaikie@gmail.com>"> <span class="fn">David Blaikie</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Undefined behavior inside constexpr function"
   href="https://bugs.llvm.org/show_bug.cgi?id=39675">bug 39675</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>dblaikie@gmail.com
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Undefined behavior inside constexpr function"
   href="https://bugs.llvm.org/show_bug.cgi?id=39675#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Undefined behavior inside constexpr function"
   href="https://bugs.llvm.org/show_bug.cgi?id=39675">bug 39675</a>
              from <span class="vcard"><a class="email" href="mailto:dblaikie@gmail.com" title="David Blaikie <dblaikie@gmail.com>"> <span class="fn">David Blaikie</span></a>
</span></b>
        <pre>As Eli mentioned - this is ill-formed, no diagnostic required. So Clang is
conforming here.

To see the error/reach the invalid case that Clang must diagnose/not accept,
you'd need to call the function in a constexpr context.

For instance, add "constexpr int i = b();" to main (or anywhere else) and clang
will diagnose this:

<source>:23:19: error: constexpr variable 'i' must be initialized by a constant
expression
    constexpr int i = b();
                  ^   ~~~
<source>:11:13: note: value 4294967294 is outside the range of representable
values of type 'int'
    return i*2/2;
            ^
<source>:18:12: note: in call to 'f(2147483647)'
    return f(i);
           ^
<source>:23:23: note: in call to 'b()'
    constexpr int i = b();
                      ^

<a href="https://godbolt.org/z/aSNE9N">https://godbolt.org/z/aSNE9N</a>

For further, the following is a valid constexpr function that must not be
diagnosed at the point of definition:

  constexpr int i(bool b) { if (b) return 3/0; return 1; }

'constexpr' doesn't guarantee that all callers can (nor must) be evaluated as a
constant. Just that some callers may. And that all of /those/ callers (the ones
in a constexpr context) must do so in a way that is well defined.

So I can write "int x[i(false)];" and get an array of length 1 - this program
is still totally conforming.

If I write "int x[i(true)];" the compiler is required to reject this program.

If I write "int x = i(true);" the program has UB and the compiler isn't
required to do anything in particular (it's not required to reject the program,
it's not required to make the program do any .particular thing, etc)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>