]> granicus.if.org Git - clang/commitdiff
Accept __declspec(dllimport) for function defined at class scope in Microsoft mode.
authorFrancois Pichet <pichet2000@gmail.com>
Tue, 29 Mar 2011 10:39:17 +0000 (10:39 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Tue, 29 Mar 2011 10:39:17 +0000 (10:39 +0000)
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

lib/Sema/SemaDecl.cpp
test/SemaCXX/MicrosoftExtensions.cpp

index 7a1492a53b553f8669125e1f6ed97601847db49c..e52082bbbfc13c7551a3227980ee6e2a5d49fbc3 100644 (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";
index 0434f48dd1a5771a54d338b89febbfd584c6bb41..094b5e05238b3f76485906c9fa45cbb28090acda 100644 (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}}
+
+}
+
+
+