[cfe-dev] Latest clang shows failure in redeclaration with dllimport

Edward Diener eldlistmailingz at tropicsoft.com
Wed May 6 15:01:26 PDT 2015


On 5/6/2015 12:10 PM, Reid Kleckner wrote:
> This was https://llvm.org/bugs/show_bug.cgi?id=20746.
>
> In simple cases, this is just a warning:
> $ cat t.c
> void Sleep(unsigned long MS);
> void __declspec(dllimport) Sleep(unsigned long MS);
> $ clang -c t.c
> t.c:2:28: warning: redeclaration of 'Sleep' should not add 'dllimport'
> attribute [-Wdll-attribute-on-redeclaration]
>
> If you declare it, use it, and then add dll attributes, we turn it into
> an error:
> $ cat t.c
> void Sleep(unsigned long MS);
> void f() { Sleep(0); }
> void __declspec(dllimport) Sleep(unsigned long MS);
> $ clang -c t.c
> t.c:3:28: error: redeclaration of 'Sleep' cannot add 'dllimport' attribute
>
> We decided on this behavior because dllimport-ness affects how the
> symbol can be used in constant expressions. For example, this needs
> dynamic initialization:
> int __declspec(dllimport) foo;
> int *p = &foo;
>
> This does not:
> int foo;
> int *p = &foo;
>
> If you declare foo without dllimport and than add it after we've emitted
> the initializer for p, that's a miscompile, so we won't let you do it.
>
> It also feeds into things like constexpr.

Thanks for the explanation of when it becomes an error. It will help me 
trace what is happening when it occurs,

>
> On Tue, May 5, 2015 at 10:03 AM, Edward Diener
> <eldlistmailingz at tropicsoft.com
> <mailto:eldlistmailingz at tropicsoft.com>> wrote:
>
>     Testing some Boost libraries with the latest build of clang I get
>     the failure:
>
>     c:/mingw/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:63:29: note: previous
>     declaration is here
>        extern "C" void __stdcall Sleep( unsigned long ms );
>                                  ^
>     1 error generated.
>
>     Has clang now changed so that a redeclaration with or without a
>     'dllimport' attribute is now an error ?
>





More information about the cfe-dev mailing list