<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 - call to consteval in immediate invocation context fails"
   href="https://bugs.llvm.org/show_bug.cgi?id=51840">51840</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>call to consteval in immediate invocation context fails
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++2a
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Reduced from <a href="https://stackoverflow.com/questions/69166564">https://stackoverflow.com/questions/69166564</a>

The following code fails on clang >= 11.0 (including trunk)
-----

consteval int f(int) { return 1; }

template <typename T>
consteval bool g(T a) 
{
    int n = f(a);   // error here
    return true;
}

static_assert(g(2));

-----

with 
 error: call to consteval function 'f' is not a constant expression
 note: read of non-const variable 'a' is not allowed in a constant expression

This seems incorrect. The evaluation of `f` is in an immediate context, i.e.
inside `g` so `f(a)` should be a constant expression. Also, the error only
appears if `g` is a template, and if the result of `f(a)` is stored in a local
variable. GCC accepts the code.</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>