[LLVMbugs] [Bug 16034] New: [-fms-compatibility] Allow ICE pointer values in case labels

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 16 10:05:07 PDT 2013


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

            Bug ID: 16034
           Summary: [-fms-compatibility] Allow ICE pointer values in case
                    labels
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: reid.kleckner at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

MSVC accepts this code:

typedef void *HKEY;
#define HKEY_CLASSES_ROOT (( HKEY ) (ULONG_PTR)((LONG)0x80000000) )
...
const wchar_t *HKEYToString(const HKEY key) {
  switch (reinterpret_cast<LONG_PTR>(key)) {
    case HKEY_CLASSES_ROOT:
      return L"HKEY_CLASSES_ROOT";
    case HKEY_CURRENT_CONFIG:
      return L"HKEY_CURRENT_CONFIG";
    case HKEY_CURRENT_USER:
      return L"HKEY_CURRENT_USER";
    case HKEY_LOCAL_MACHINE:
      return L"HKEY_LOCAL_MACHINE";
    case HKEY_USERS:
      return L"HKEY_USERS";
  }
  return L"unknown";
}

It does not accept 'switch (key)', so it must be converting the case label
values to LONG_PTR.

If I try to cast the label values back to LONG_PTR, clang says reinterpret_cast
conversions are not allowed in case labels:

registry.cc:24:10: error: case value is not a constant expression
    case (LONG_PTR)HKEY_USERS:
         ^~~~~~~~~~~~~~~~~~~~
registry.cc:24:10: note: cast that performs the conversions of a
reinterpret_cast is not allowed in a constant expression

It seems the least invasive way to get clang to accept this code is to fall
back to an if/else chain, unless clang adds support for this as an extension.

-- 
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/20130516/fa4652c9/attachment.html>


More information about the llvm-bugs mailing list