Verification of the function pointer type invocation agreement

How to check at compile time that a function pointer has an __stdcall calling __stdcall ?

Something like

 void foo() {} static_assert(is_stdcall<decltype(&foo)>::value, "foo() must be stdcall"); 

or at least

 must_be_stdcall<T>(); // compiler error or warning if not stdcall 
+6
c ++ visual-c ++ calling-convention
source share
1 answer

MSVC has a C4440 compiler warning :

 // library code #pragma warning(push) #pragma warning(error: 4440) template<typename F> void must_be_stdcall(F*) { typedef F __stdcall* T; } #pragma warning(pop) // test code void __stdcall stdcall_fn() {} void __cdecl cdecl_fn() {} int main() { must_be_stdcall(&stdcall_fn); // OK must_be_stdcall(&cdecl_fn); // error } 

It could be typedef decltype(foo) __stdcall* T; , where foo is a function (note that there should be foo , not &foo ), but it does not work with static member functions.

+5
source share

All Articles