Index: lib/Sema/SemaDeclAttr.cpp =================================================================== --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -6485,6 +6485,16 @@ D->setInvalidDecl(); } } + //In Microsoft C++ mode a const variables defined in namespace scope has external + // linkage by default if the variable is declared with __declspec(dllexport). + if (auto *VD = dyn_cast(D)) { + if (getLangOpts().CPlusPlus && getLangOpts().MSVCCompat && + VD->getType().isLocalConstQualified() && + VD->hasAttr() && + VD->getDefinition()) { + VD->setStorageClass(SC_Extern); + } + } } // Helper for delayed processing TransparentUnion attribute. Index: test/Sema/dllexport.c =================================================================== --- test/Sema/dllexport.c +++ test/Sema/dllexport.c @@ -66,6 +66,8 @@ __declspec(dllexport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllexport'}} } +// const variables +__declspec(dllexport) int const x = 3; //===----------------------------------------------------------------------===//