<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - MSVC rejects dllexport on things in anonymous namespaces but MSVC accepts"
   href="https://bugs.llvm.org/show_bug.cgi?id=39415">39415</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>MSVC rejects dllexport on things in anonymous namespaces but MSVC accepts
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rnk@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>