<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Bad errors if exceeding constexpr iteration limit"
   href="https://bugs.llvm.org/show_bug.cgi?id=40089">40089</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Bad errors if exceeding constexpr iteration limit
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>blubban@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Input:

 constexpr int x(int y)
 {
     return y;
 }
 constexpr int z()
 {
     for (int i=0;i<0x7fffffff;i++)
         if (x(i) != x(i)) return 1;
     return 0;
 }

 template<int e> int ee() { return e; }

 int p() { return ee<z()>(); }


Expected: Anything containing
 <source>:2:1: note: constexpr evaluation hit maximum step limit; possible
infinite loop?
 {
 ^
 <source>:8:21: note: in call to 'x(209714)'
         if (x(i) != x(i)) return 1;
                     ^

Actual:
 <source>:14:18: error: no matching function for call to 'ee'
  int p() { return ee<z()>(); }
                  ^~~~~~~
 <source>:12:21: note: candidate template ignored: invalid explicitly-specified
argument for template parameter 'e'
  template<int e> int ee() { return e; }
                      ^
and nothing else.


GCC gives much better results:
 <source>: In function 'int p()':
 <source>:14:26: error: no matching function for call to 'ee<z()>()'
  int p() { return ee<z()>(); }
                           ^
 <source>:12:21: note: candidate: 'template<int e> int ee()'
  template<int e> int ee() { return e; }
                      ^~
 <source>:12:21: note:   template argument deduction/substitution failed:
 <source>:14:22:   in 'constexpr' expansion of 'z()'
 <source>:7:5: error: 'constexpr' loop iteration count exceeds limit of 262144
(use -fconstexpr-loop-limit= to increase the limit)
      for (int i=0;i<0x7fffffff;i++)
      ^~~
 <source>:14:22: note: in template argument for type 'int'
  int p() { return ee<z()>(); }
                      ~^~

Bonus: Replace the last line with
 template int ee<z()>();
to get bad errors from both Clang and GCC. Alternatively,
 constexpr bool w = z();
yields good errors from both; inlining x() also gives good errors. (GCC
mentions -fconstexpr-loop-limit=, but Clang doesn't mention -fconstexpr-steps=;
not sure if that's intentional.)</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>