[llvm-bugs] [Bug 50711] New: Bug: undefined behavior of constexpr static_cast from int to unscoped enum without fixed type outside range compiles fine on C++17

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 14 23:29:09 PDT 2021


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

            Bug ID: 50711
           Summary: Bug: undefined behavior of constexpr static_cast from
                    int to unscoped enum without fixed type outside range
                    compiles fine on C++17
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: carlosgalvezp 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

Hi,

The following code is undefined behavior in C++17. And undefined behavior is
not allowed in constant expressions - the compiler is required to diagnose it.
Adapted from cppreference:

enum foo { a = 0, b = 1 }; 
constexpr foo x = static_cast<foo>(123); // undefined behavior since C++17

However Clang happily compiles this code:

https://godbolt.org/z/bzhWMxqoE

-- 
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/20210615/7665e1ba/attachment-0001.html>


More information about the llvm-bugs mailing list