Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -10678,6 +10678,15 @@ return; } + //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 (getLangOpts().CPlusPlus && getLangOpts().MSVCCompat && + VDecl->getType().isLocalConstQualified() && + VDecl->hasAttr() && + VDecl->getDefinition()) { + VDecl->setStorageClass(SC_Extern); + } + if (VDecl->hasLocalStorage()) setFunctionHasBranchProtectedScope(); Index: test/Sema/dllexport.c =================================================================== --- test/Sema/dllexport.c +++ test/Sema/dllexport.c @@ -66,7 +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; //===----------------------------------------------------------------------===// // Functions