[llvm-bugs] [Bug 39939] New: reinterpret_cast rejects cast from const array to function pointer

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 10 11:50:22 PST 2018


            Bug ID: 39939
           Summary: reinterpret_cast rejects cast from const array to
                    function pointer
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: myriachan at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Clang++ rejects reinterpret_cast from const array to function pointer type,
claiming incorrectly that the cast removes qualifiers.  The same cast is
permitted as a C cast, probably because C casts are allowed to remove

x86-32/x86-64 only for this example, naturally.

<source>:7:14: error: reinterpret_cast from 'const unsigned char *' to
'unsigned int (*)()' casts away qualifiers
    return (*reinterpret_cast<unsigned (*)()>(s_ret))();

#include <cstdio>

unsigned Meow()
    static const unsigned char __attribute__((__section__(".text")))
        s_ret[] = { 0xB8, 0xEF, 0xBE, 0xAD, 0xDE, 0xC3 };
    return (*reinterpret_cast<unsigned (*)()>(s_ret))();
    //works fine: return ((unsigned (*)()) s_ret)();

int main()
    std::printf("Meow returned %08X\n", Meow());
    return 0;

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/20181210/2a5dd14e/attachment.html>

More information about the llvm-bugs mailing list