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: unassignedclangb...@nondot.org
          Reporter: r...@google.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to