-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Closed as not planned
Closed as not planned
Copy link
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issueDoes the clang frontend diverge from msvc on this issuequestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Description
GCC and MSVC both allow a reinterpret_cast to convert from a const void* to void (*)(void*).
Clang refuses because we are "casting away qualifiers" (const), but there is no qualifier to add on the function-pointer side. There is no syntax for assigning values into a function pointer and there is no possible addition of const into the function pointer type which makes the cast allowed.
This can be worked around by using const_cast to strip the const off the void*, or by using a C-style cast, but this seems like it shouldn't be necessary, and no other mainstream compiler requires it.
Example: https://godbolt.org/z/7rxqss7nT
using FuncPtr = void (*)(void*);
extern "C" const void* Lookup(const void* OriginalFunction);
FuncPtr MakeVoidFuncPtr(const void* Func) {
return reinterpret_cast<FuncPtr>(Lookup(Func));
}
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issueDoes the clang frontend diverge from msvc on this issuequestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!