[llvm-bugs] [Bug 44415] New: -Wconstant-evaluated erroneously claims an is_constant_evaluated() will always evaluate as true

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 31 03:36:12 PST 2019


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

            Bug ID: 44415
           Summary: -Wconstant-evaluated erroneously claims an
                    is_constant_evaluated() will always evaluate as true
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tonyelewis at hotmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Thanks for the work to emit a warning on `if constexpr
(std::is_constant_evaluated())` (https://bugs.llvm.org/show_bug.cgi?id=42977),
which I think is a great idea. Here's a wrinkle...

Using Godbolt's clang trunk (31st December 2019,
6185dc0eb3ad35e1f85f2ab1038ca978563099f4) with `-std=c++2a -O1` to compile the
following:


#include <type_traits>

int main() {
    int b = 2;
    const int a = std::is_constant_evaluated() ? b : 1;
    return a;
}


I get this warning:


<source>:5:19: warning: 'std::is_constant_evaluated' will always evaluate to
'true' in a manifestly constant-evaluated expression [-Wconstant-evaluated]

    const int a = std::is_constant_evaluated() ? b : 1;

                  ^


...yet the generated code is returning 1, showing that the
`is_constant_evaluated()` has evaluated to false and thus that the warning is
incorrect.

The example originates from a snippet in Daveed Vandevoorde's "C++ Constants"
C++Now 2019 talk (around 39m00s).

-- 
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/20191231/810418d8/attachment.html>


More information about the llvm-bugs mailing list