[cfe-users] Clang (with Visual Studio) wrongly complains about missing variables
John Emmas via cfe-users
cfe-users at lists.llvm.org
Thu Sep 23 03:34:45 PDT 2021
On 22/09/2021 18:21, Reid Kleckner via cfe-users wrote:
> Looking back in the thread, I found the example code, and I see that
> MSVC refuses to inline this helper, but clang will inline it. I
> believe clang is permitted to inline it, MSVC will export the static
> data member (_the_keyboard), so everything should work as long as you
> provide a definition of _the_keyboard in the DLL and set -DBUILDING_DLL.
>
Thanks for coming in on this, Reid. As Jeff suggested, I transferred the
question to llvm-dev where there's a small discussion going on now. I
must admit though, my personal view is that declaring something as
__declspec(dllimport) should automatically exclude it from being inlined
(I'm pretty sure that's what Microsoft itself does...)
Ultimately, the main advantage of a DLL is that it offers dynamic
linkage. In other words, DLL features can be updated simply by updating
the DLL (i.e. without needing to update all the apps which use it). In
the dim old days this could lead to something called "DLL Hell" but
WinSxS has largely consigned that to history now. So whilst inlining
code from a DLL might seem like a good idea, it throws away the main
advantage of DLL's without offering anything better.
Over on llvm-dev I'm trying to persuade them that declaring something as
__declspec(dllimport) should automatically exclude it from being
inlined. And to be honest, I'd be quite surprised if that's not what
Microsoft intended.
John
More information about the cfe-users
mailing list