Wrong calling convention for Clang++, all good in MSVC

Multi tool use
Multi tool use


Wrong calling convention for Clang++, all good in MSVC



I am using clang power tools to compile a project which is usually compiled using visual studio. In boost's lwm_win32.hpp header (yes we are using an old version of boost and currently cannot update) I get an error reading



function declared 'stdcall' here was previously declared without calling convention



the line in question is


extern "C" __declspec(dllimport) long __stdcall InterlockedExchange(long volatile *, long);



I don't get any errors or warnings for this line when compiling with visual studio. Interestingly I don't get any even if I manually change the calling convention from __stdcall to __cdecl.
Clang tells me which previous declaration it has seen. By manually inspecting this location I would say clang is right. After deciphering all preprocessor defines I would also say __cdecl is what should be seen by visual studio. The official documentation, however, does not mention a specific calling convention.


__stdcall


__cdecl


__cdecl



So basically I am unsure what the root of the problem is. Visual studio accepting any calling convention in the declaration? Clang not seeing the correct declaration due to some preprocessor macros set to the wrong value? Boost declaring the wrong calling convention? I must admit I am confused.



Visual Studio version is 2015 Update 3.



Clang++ version is 6.0.0 called with parameter -fms-compatibility-version=19.


-fms-compatibility-version=19





Does MSVC actually emit a call to a library function instead of treating it as an intrinsic and inlining lock cmpxchg? You'd want it defined in terms of an intrinsic, because a function call takes more code-size than inlining the single instruction.
– Peter Cordes
1 hour ago



lock cmpxchg





Note that "the official documentation" is for _InterlockedExchange - with a leading underscore - which is not a function, but the intrinsic Peter Cordes expects. InterlockedExchange from a DLL is something different. If you really are on boost 1.32 (like in the link), that might not be correctly configured for clang 6.0?
– Bo Persson
55 mins ago



_InterlockedExchange


InterlockedExchange





@Peter According to the docs it does now, yes, but I think the compiler still needs to see the (appropriate) function prototype.
– Paul Sanders
4 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

S,7oyjOBQSaMaMSjj5,XV86xA IZPHX4aVnwl MKsB yXiby9 AE8,LM230L
6 XZyBWlb7L7,kOWsH2jzwQFt681BDaJp77AaQdzOqXeItRbDMuo,YOyaVzeVqCD,2T4P,pRsWRwwoH4jS

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications