From: Francois Pichet Date: Tue, 29 Mar 2011 10:39:17 +0000 (+0000) Subject: Accept __declspec(dllimport) for function defined at class scope in Microsoft mode. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b613cd6862a80126666c46a41de36c1ba7704c2e;p=clang Accept __declspec(dllimport) for function defined at class scope in Microsoft mode. This fixes a bunch of errors when compiling MSVC header files with the -DDLL flag. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128457 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7a1492a53b..e52082bbbf 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -5701,7 +5701,9 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) { DLLImportAttr *DA = FD->getAttr(); if (DA && (!FD->getAttr())) { // dllimport attribute cannot be directly applied to definition. - if (!DA->isInherited()) { + // Microsoft accepts dllimport for functions defined within class scope. + if (!DA->isInherited() && + !(LangOpts.Microsoft && FD->getLexicalDeclContext()->isRecord())) { Diag(FD->getLocation(), diag::err_attribute_can_be_applied_only_to_symbol_declaration) << "dllimport"; diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index 0434f48dd1..094b5e0523 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -114,3 +114,16 @@ struct X0 { enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} SomeValue = 0x100000000 }; + + +class AAA { +__declspec(dllimport) void f(void) { } +void f2(void); +}; + +__declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}} + +} + + +