]> granicus.if.org Git - clang/commitdiff
PR19713: Don't warn on unused static inline functions, even if the 'inline' was
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 11 May 2014 21:25:24 +0000 (21:25 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 11 May 2014 21:25:24 +0000 (21:25 +0000)
implied by 'constexpr'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208511 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-unused-filescoped.cpp

index b7c681f08e2e705df4d1183be6b5523a3a054071..67c78ce904adeabdbd342e2bb0ef416274ac84ca 100644 (file)
@@ -1219,8 +1219,7 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const {
         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::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const {
   }
 
   // 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);
 }
 
index b0af5b33227069d853a336af3fc1d79f765d4f2e..df4c47e71787d9d03f8a56fa8525bc1f25566344 100644 (file)
@@ -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__((used)); }
 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