[PATCH] D45978: dllexport const variables must have external linkage.
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 6 11:05:43 PST 2019
aaron.ballman added a comment.
Can you add tests for C mode as well, as it seems the behavior differs there. Given:
__declspec(dllexport) int const x = 3;
__declspec(dllexport) const int y;
extern int const z = 4;
int main() {
int a = x + y + z;
return a;
}
I get:
C:\Users\aballman.GRAMMATECH\source\repos\ConsoleApplication1\ConsoleApplication1>cl -c ConsoleApplication1.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27026.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
ConsoleApplication1.cpp
ConsoleApplication1.cpp(2): error C2734: 'y': 'const' object must be initialized if not 'extern'
C:\Users\aballman.GRAMMATECH\source\repos\ConsoleApplication1\ConsoleApplication1>cl -c /Tc ConsoleApplication1.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27026.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
ConsoleApplication1.cpp
C:\Users\aballman.GRAMMATECH\source\repos\ConsoleApplication1\ConsoleApplication1>dumpbin /symbols ConsoleApplication1.obj | grep External
008 00000000 SECT3 notype External | x
009 00000004 UNDEF notype External | y
00A 00000004 SECT3 notype External | z
00D 00000000 SECT4 notype () External | main
After commenting out the declaration and use of `y` and recompiling in C++ mode:
C:\Users\aballman.GRAMMATECH\source\repos\ConsoleApplication1\ConsoleApplication1>dumpbin /symbols ConsoleApplication1.obj | grep External
008 00000000 SECT3 notype External | ?z@@3HB (int const z)
00B 00000000 SECT4 notype () External | main
================
Comment at: test/Sema/dllexport-1.cpp:2
+// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -fms-extensions -verify %s
+// RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -fms-extensions -verify -std=c++11 %s
+
----------------
Can remove some extra whitespace before `-fsyntax-only` (same is true in the other test as well).
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D45978/new/
https://reviews.llvm.org/D45978
More information about the cfe-commits
mailing list