]> granicus.if.org Git - clang/commitdiff
An inline function redeclaration does not drop the dllimport attribute
authorHans Wennborg <hans@hanshq.net>
Thu, 22 May 2014 15:46:15 +0000 (15:46 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 22 May 2014 15:46:15 +0000 (15:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209449 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Rewriter/missing-dllimport.c
test/Sema/dllimport.c

index d65ba117dc8db04bef3f3e0bbf85723724c5d5f6..88f099f96d299c4ba904d461af7a0330a71ed548 100644 (file)
@@ -4898,9 +4898,11 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
 
   // A redeclaration is not allowed to drop a dllimport attribute, the only
   // exception being inline function definitions.
-  // FIXME: Handle inline functions.
   // NB: MSVC converts such a declaration to dllexport.
-  if (OldImportAttr && !HasNewAttr) {
+  bool IsInline =
+      isa<FunctionDecl>(NewDecl) && cast<FunctionDecl>(NewDecl)->isInlined();
+
+  if (OldImportAttr && !HasNewAttr && !IsInline) {
     S.Diag(NewDecl->getLocation(),
            diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
       << NewDecl << OldImportAttr;
index 1e4689fba0db33c9c548a66ef1ace60f3fae1786..a09ebff44db66eb0df7c37a1fd468ec808c4e4ff 100644 (file)
@@ -1,19 +1,8 @@
-// RUN: not %clang_cc1 -triple i686-pc-win32 -fms-extensions -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-NEG %s
-// RUN: not %clang_cc1 -triple i686-pc-win32 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-POS %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -verify %s
 
-// Do not report that 'foo()' is redeclared without dllimport attribute with -fms-extensions
+// Do not report that 'foo()' is redeclared without dllimport attribute.
 // specified.  Addresses <rdar://problem/7653912>.
 
+// expected-no-diagnostics
 __declspec(dllimport) int __cdecl foo(void);
 inline int __cdecl foo() { return 0; }
-
-// This function is added just to trigger a diagnostic.  This way we can test how many
-// diagnostics we expect.
-void bar() { return 1; }
-
-// CHECK-NEG: error: void function 'bar' should not return a value
-// CHECK-NEG: 1 error generated
-// CHECK-POS: warning: 'foo' redeclared without 'dllimport' attribute: previous 'dllimport' ignored
-// CHECK-POS: error: void function 'bar' should not return a value
-// CHECK-POS: 1 warning and 1 error generated
-
index fa3e2b385a429efbe013d8b1fa82008aeaff4f27..2c504d1f77b5737c3b984b2a5f69348a5bc12742 100644 (file)
@@ -118,5 +118,9 @@ __declspec(dllimport) void redecl3(); // expected-note{{previous declaration is
                       void redecl4(); // expected-note{{previous declaration is here}}
 __declspec(dllimport) void redecl4(); // expected-error{{redeclaration of 'redecl4' cannot add 'dllimport' attribute}}
 
+// Inline redeclarations are fine.
+__declspec(dllimport) void redecl5();
+inline                void redecl5() {}
+
 // External linkage is required.
 __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}