]> granicus.if.org Git - clang/commitdiff
Revert functional part of r166896 and just suppress -Wunneeded-internal-declaration...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 28 Oct 2012 07:39:29 +0000 (07:39 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 28 Oct 2012 07:39:29 +0000 (07:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166899 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6eef427731bc5c15d0d921bbf2d22b3dd4ea2bb4..0eb123105b9d4057c270e1cea0ee1e7e00154941 100644 (file)
@@ -1204,18 +1204,17 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const {
         Context.DeclMustBeEmitted(FD))
       return false;
   } else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
+    // Don't warn on variables of const-qualified or reference type, since their
+    // values can be used even if though they're not odr-used, and because const
+    // qualified variables can appear in headers in contexts where they're not
+    // intended to be used.
+    // FIXME: Use more principled rules for these exemptions.
     if (!VD->isFileVarDecl() ||
+        VD->getType().isConstQualified() ||
+        VD->getType()->isReferenceType() ||
         Context.DeclMustBeEmitted(VD))
       return false;
 
-    // If a variable is usable in constant expressions and it's not odr-used,
-    // its value may still have been used. Conservatively suppress the warning
-    // in this case.
-    const VarDecl *VDWithInit = 0;
-    if (VD->isUsableInConstantExpressions(Context) &&
-        VD->getAnyInitializer(VDWithInit) && VDWithInit->checkInitIsICE())
-      return false;
-
     if (VD->isStaticDataMember() &&
         VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
       return false;
index 328d8bbb5b4051b569a97364564875aa3c6743b2..ad896b5212044b7fcd1df76e8ed23def47762f7c 100644 (file)
@@ -95,8 +95,9 @@ namespace test5 {
   int f(int &);
   int k = f(r);
 
-  static const int m = n; // expected-warning {{not needed and will not be emitted}}
+  // FIXME: We should produce warnings for both of these.
+  static const int m = n;
   int x = sizeof(m);
-  static const double d = 0.0; // expected-warning {{not needed and will not be emitted}}
+  static const double d = 0.0;
   int y = sizeof(d);
 }