[llvm-bugs] [Bug 39415] New: MSVC rejects dllexport on things in anonymous namespaces but MSVC accepts
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Oct 23 17:02:57 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=39415
Bug ID: 39415
Summary: MSVC rejects dllexport on things in anonymous
namespaces but MSVC accepts
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: rnk at google.com
CC: llvm-bugs at lists.llvm.org
Consider:
$ cat t.cpp
namespace {
int __declspec(dllexport) foo() { return 1; }
int __declspec(dllexport) bar = 42;
}
$ cl -c t.cpp
# no errors
$ clang-cl -c t.cpp
t.cpp(2,27): error: '(anonymous namespace)::foo' must have external linkage
when declared 'dllexport'
int __declspec(dllexport) foo() { return 1; }
^
t.cpp(3,27): error: '(anonymous namespace)::bar' must have external linkage
when declared 'dllexport'
int __declspec(dllexport) bar = 42;
^
However, if you use 'static', MSVC doesn't like it:
$ cat t.cpp
static int __declspec(dllexport) foo() { return 1; }
static int __declspec(dllexport) bar = 42;
$ cl -c t.cpp
t.cpp(1): error C2201: 'foo': must have external linkage in order to be
exported/imported
t.cpp(2): error C2201: 'bar': must have external linkage in order to be
exported/imported
We followed them in implementing our version of this diagnostic.
I think it's pretty clear that MSVC's behavior is just behavior that emerged
from past C++ standard guidance that things in anonymous namespaces used to
have external linkage, but now they do not. MSVC probably reduced their linkage
to static, ran into compatibility issues with code like this, and went back to
their old behavior.
I'm mostly filing this so I can close it as WONTFIX, but if more users run into
this over time, please comment here, and we can re-evaluate.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181024/0b545038/attachment.html>
More information about the llvm-bugs
mailing list