[LLVMbugs] [Bug 12614] New: static_cast fails to cast enum with fixed underlying type to std::underlying_type of enum type

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Apr 21 10:21:21 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12614

             Bug #: 12614
           Summary: static_cast fails to cast enum with fixed underlying
                    type to std::underlying_type of enum type
           Product: clang
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: st at quanttec.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The following code fails to compile with
Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
-std=c+11 -stdlib=libc++

--

#include <cstdint>
#include <type_traits>

enum class TestEnum : uint32_t {
    value = 0
};

// the following assert succeeds
static_assert(std::is_same<uint32_t,
std::underlying_type<TestEnum>::type>::value, "");

void test() {
   // the next line compiles ...
   uint32_t t1 = static_cast<uint32_t>(TestEnum::value); 
   // ... but the next one doesn't
   uint32_t t2 =
static_cast<std::underlying_type<TestEnum>::type>(TestEnum::value);
   // error: static_cast from 'TestEnum' to
'std::underlying_type<TestEnum>::type' (aka 'unsigned int') is not allowed
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list