[llvm-bugs] [Bug 51840] New: call to consteval in immediate invocation context fails

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 13 18:34:33 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51840

            Bug ID: 51840
           Summary: call to consteval in immediate invocation context
                    fails
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: cgnitash at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Reduced from https://stackoverflow.com/questions/69166564

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210914/a0e7df20/attachment.html>


More information about the llvm-bugs mailing list