[PATCH] D117569: Constexpr not supported with __declspec(dllimport).

Zahira Ammarguellat via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 20 18:19:39 PST 2022


zahiraam added a comment.

In D117569#3259928 <https://reviews.llvm.org/D117569#3259928>, @majnemer wrote:

> Your example is different from mine as it nests the constexpr variable inside the function rather than having it at translation-unit scope.

And I suppose we are interested in the latter?

In D117569#3259928 <https://reviews.llvm.org/D117569#3259928>, @majnemer wrote:

> Your example is different from mine as it nests the constexpr variable inside the function rather than having it at translation-unit scope.

Aargh! Getting lots of link errors with various tests I tried.
Tried this:
dll.cpp:
__declspec(dllexport) int& get() {

  extern int __declspec(dllimport) dll_import_int;
  constexpr int& dll_import_constexpr_ref = dll_import_int;
  
  return dll_import_constexpr_ref;

}

testapp.cpp:
extern int& __declspec(dllimport) get();

int main() {

  get();
  
  return 0;

}

$ cl dll.cpp /LD /EHsc
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30133 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

dll.cpp
Microsoft (R) Incremental Linker Version 14.29.30133.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:dll.dll
/dll
/implib:dll.lib
dll.obj

  Creating library dll.lib and object dll.exp

dll.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) int dll_import_int" (__imp_?dll_import_int@@3HA) referenced in function "int & __cdecl get(void)" (?get@@YAAEAHXZ)
dll.dll : fatal error LNK1120: 1 unresolved externals
$
Can't seem to find the right combination to find the potential bug!

Would that be enough to show that there is a MS bug?

extern int __declspec(dllimport) dll_import_int;
constexpr int& dll_import_constexpr_ref = dll_import_int;

int f() { return dll_import_constexpr_ref; }
int main() { return f(); }

Compiled with clang:
$ dumpbin /symbols a.o | grep dll
010 00000000 UNDEF  notype       External     | __imp_?dll_import_int@@3HA (__declspec(dllimport) int dll_import_int)
012 00000000 SECT5  notype       External     | ?dll_import_constexpr_ref@@3AEAHEA (int & dll_import_constexpr_ref)
013 00000000 UNDEF  notype       External     | ?dll_import_int@@3HA (int dll_import_int)

Compiled with MSVC:
$ dumpbin /symbols a.obj | grep dll
007 00000000 UNDEF  notype       External     | ?dll_import_int@@3HA (int dll_import_int)
015 00000000 SECT6  notype       Static       | ?dll_import_constexpr_ref@@3AEAHEA (int & dll_import_constexpr_ref)
$


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117569/new/

https://reviews.llvm.org/D117569



More information about the cfe-commits mailing list