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.

llvm-svn: 128457
This commit is contained in:
Francois Pichet 2011-03-29 10:39:17 +00:00
parent ffce245700
commit 3096d209bf
2 changed files with 16 additions and 1 deletions

View File

@ -5701,7 +5701,9 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
DLLImportAttr *DA = FD->getAttr<DLLImportAttr>();
if (DA && (!FD->getAttr<DLLExportAttr>())) {
// 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";

View File

@ -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}}
}