[cfe-commits] r166899 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/warn-unused-filescoped.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Sun Oct 28 00:39:29 PDT 2012
Author: rsmith
Date: Sun Oct 28 02:39:29 2012
New Revision: 166899
URL: http://llvm.org/viewvc/llvm-project?rev=166899&view=rev
Log:
Revert functional part of r166896 and just suppress -Wunneeded-internal-declaration for reference types for now. This needs more work; the cases we currently miss are a bit random.
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=166899&r1=166898&r2=166899&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 28 02:39:29 2012
@@ -1204,18 +1204,17 @@
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;
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=166899&r1=166898&r2=166899&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp Sun Oct 28 02:39:29 2012
@@ -95,8 +95,9 @@
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);
}
More information about the cfe-commits
mailing list