C++ says that reinterpret_casting an object pointer to a function pointer is conditionally supported. However, there seems to be implementation divergence on what happens if the object pointer is cv-qualified. GCC allows casts from cv object * to function pointer, but Clang and Visual C++ do not.
I mentioned this some years ago as a possible defect report, and I sent a request for one, but it never got filed.
Should something like this be a defect report? What is the correct interpretation of the Standard on this? Being a conditionally supported operation, is either interpretation allowed?
Function types have no cv qualification in the normal sense. A cv-qualified member function is referring to the "this" parameter, not the constness of the function itself. Is a cast to function type removing a cv qualifier when functions having them is nonsensical to begin with?
#if !defined(__x86_64__) && !defined(_M_X64)
#error "This is an x86-64-only program"
#pragma code_seg(push, ".text")
#define EXECUTABLE_SEGMENT __declspec(allocate(".text"))
#define EXECUTABLE_SEGMENT [[gnu::section(".text.meow")]]
#error "Unknown platform"
// movl $0x12345678, %eax
// retEXECUTABLE_SEGMENT const std::uint8_t s_code =
0xB8, 0x78, 0x56, 0x34, 0x12, 0xC3
// an intervening std::uintptr_t cast works with all compilers relevant here int result = reinterpret_cast<int (*)()>(s_code)();