[PATCH] D45978: dllexport const variables must have external linkage.

Zahira Ammarguellat via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 14 02:24:14 PST 2019


zahiraam marked an inline comment as done.
zahiraam added inline comments.


================
Comment at: lib/Sema/SemaDecl.cpp:11370
 
+    // In Microsoft C++ mode, a const variable defined in namespace scope has
+    // external linkage by default if the variable is declared with
----------------
aaron.ballman wrote:
> thakis wrote:
> > Even in unnamed namespaces?
> That would definitely be good to test.
It looks like not. 

ksh-3.2$ cat test4.cpp
namespace {
__declspec(dllexport) int const x = 3;
}

int main ()
{
  int y = x + 10;

  return y;
}

ksh-3.2$ cl -c test4.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test4.cpp
ksh-3.2$ dumpbin /symbols test4.obj | grep External
**008 00000000 SECT3  notype ()    External     | main**
ksh-3.2$

ksh-3.2$ clang -c test4.cpp
test4.cpp:2:33: error: '(anonymous namespace)::x' must have external linkage when declared 'dllexport'
__declspec(dllexport) int const x = 3;
                                ^
1 error generated.
ksh-3.2$

So the diag shouldn't go off when the variable is in an anonymous namespace? Do you agree?



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

https://reviews.llvm.org/D45978





More information about the cfe-commits mailing list