r208511 - PR19713: Don't warn on unused static inline functions, even if the 'inline' was

Richard Smith richard-llvm at metafoo.co.uk
Sun May 11 14:25:25 PDT 2014


Author: rsmith
Date: Sun May 11 16:25:24 2014
New Revision: 208511

URL: http://llvm.org/viewvc/llvm-project?rev=208511&view=rev
Log:
PR19713: Don't warn on unused static inline functions, even if the 'inline' was
implied by 'constexpr'.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=208511&r1=208510&r2=208511&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun May 11 16:25:24 2014
@@ -1219,8 +1219,7 @@ bool Sema::ShouldWarnIfUnusedFileScopedD
         return false;
     } else {
       // 'static inline' functions are defined in headers; don't warn.
-      if (FD->isInlineSpecified() &&
-          !isMainFileLoc(*this, FD->getLocation()))
+      if (FD->isInlined() && !isMainFileLoc(*this, FD->getLocation()))
         return false;
     }
 
@@ -1245,6 +1244,8 @@ bool Sema::ShouldWarnIfUnusedFileScopedD
   }
 
   // Only warn for unused decls internal to the translation unit.
+  // FIXME: This seems like a bogus check; it suppresses -Wunused-function
+  // for inline functions defined in the main source file, for instance.
   return mightHaveNonExternalLinkage(D);
 }
 

Modified: cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp?rev=208511&r1=208510&r2=208511&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp Sun May 11 16:25:24 2014
@@ -32,6 +32,13 @@ namespace test7
   inline void bar(int, int) { }
 };
 
+namespace pr19713 {
+#if __cplusplus >= 201103L
+  static constexpr int constexpr1() { return 1; }
+  constexpr int constexpr2() { return 2; }
+#endif
+}
+
 #else
 #define HEADER
 #include "warn-unused-filescoped.cpp"
@@ -193,4 +200,12 @@ void bar() { void func() __attribute__((
 static void func() {}
 }
 
+namespace pr19713 {
+#if __cplusplus >= 201103L
+  // FIXME: We should warn on both of these.
+  static constexpr int constexpr3() { return 1; } // expected-warning {{unused}}
+  constexpr int constexpr4() { return 2; }
+#endif
+}
+
 #endif





More information about the cfe-commits mailing list