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

Reid Kleckner rnk at google.com
Wed May 6 09:10:42 PDT 2015


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.

On Tue, May 5, 2015 at 10:03 AM, Edward Diener <
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 ?
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150506/4e12f2f2/attachment.html>


More information about the cfe-dev mailing list