[cfe-dev] Latest clang and dllimport

Hans Wennborg hans at chromium.org
Tue Jul 21 14:39:05 PDT 2015


Hi Edward,

I'm using this code to reproduce the issue you're seeing:

  extern "C" void sleep(unsigned ms);
  void f() {
    sleep(1000);
  }
  extern "C" __declspec(dllimport) void sleep(unsigned ms);

Compiling with "clang -target i686-pc-win32 -c a.cc" produces the
error you describe.

This produces an error both with both 3.5, 3.6 and trunk for me. Is it
possible that something has changed in your code, or that something is
getting #ifdef'ed differently based on the clang version?

The problem here is that Clang doesn't want to change the
"dllimport"-ness of sleep() after it has been called. If you try to
add the dllimport attribute before sleep() has been used, Clang will
just warn.

 - Hans

On Tue, Jul 21, 2015 at 12:36 PM, Edward Diener
<eldlistmailingz at tropicsoft.com> wrote:
> In the latest clang built from source, if a function is mismatched as to a
> difference in dllimport attributes clang produces an error. As in:
>
> C:\Utilities\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\i686-w64-mingw32\include\synchapi.h:127:26:
> error: redeclaration of 'Sleep' cannot add 'dllimport' attribute
>   WINBASEAPI VOID WINAPI Sleep (DWORD dwMilliseconds);
>                          ^
> ..\..\..\boost/smart_ptr/detail/yield_k.hpp:67:29: note: previous
> declaration is here
>   extern "C" void __stdcall Sleep( unsigned long ms );
>
> Changing the latter to:
>
>   extern "C" __declspec(dllimport) void __stdcall Sleep( unsigned long ms );
>
> fixes the problem for clang.
>
> Earlier versions of clang ( 3.4.1, 3.5.2, 3.6.1 ) did not have this problem.
> Is there a __has_feature or __has_extension that I can use to test this
> change in the latest clang ? The previous versions are also happy with the
> __declspec(dllimport) added in the declaration so even without a
> __has_feature or __has_extension I can just test for clang on Windows, but I
> like to be as precise as possible in Boost code.



More information about the cfe-dev mailing list