r190437 - Fix regression from r190382.
Eli Friedman
eli.friedman at gmail.com
Tue Sep 10 14:10:25 PDT 2013
Author: efriedma
Date: Tue Sep 10 16:10:25 2013
New Revision: 190437
URL: http://llvm.org/viewvc/llvm-project?rev=190437&view=rev
Log:
Fix regression from r190382.
Make sure we perform the correct "referenced-but-not-used" check for
static member constants.
Fixes bug reported on cfe-commits by Alexey Samsonov.
Modified:
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=190437&r1=190436&r2=190437&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Tue Sep 10 16:10:25 2013
@@ -358,6 +358,15 @@ static bool ShouldRemoveFromUnused(Sema
}
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
+ // If a variable usable in constant expressions is referenced,
+ // don't warn if it isn't used: if the value of a variable is required
+ // for the computation of a constant expression, it doesn't make sense to
+ // warn even if the variable isn't odr-used. (isReferenced doesn't
+ // precisely reflect that, but it's a decent approximation.)
+ if (VD->isReferenced() &&
+ VD->isUsableInConstantExpressions(SemaRef->Context))
+ return true;
+
// UnusedFileScopedDecls stores the first declaration.
// The declaration may have become definition so check again.
const VarDecl *DeclToCheck = VD->getDefinition();
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=190437&r1=190436&r2=190437&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 10 16:10:25 2013
@@ -1220,14 +1220,6 @@ bool Sema::ShouldWarnIfUnusedFileScopedD
if (!isMainFileLoc(*this, VD->getLocation()))
return false;
- // If a variable usable in constant expressions is referenced,
- // don't warn if it isn't used: if the value of a variable is required
- // for the computation of a constant expression, it doesn't make sense to
- // warn even if the variable isn't odr-used. (isReferenced doesn't
- // precisely reflect that, but it's a decent approximation.)
- if (VD->isReferenced() && VD->isUsableInConstantExpressions(Context))
- return false;
-
if (Context.DeclMustBeEmitted(VD))
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=190437&r1=190436&r2=190437&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp Tue Sep 10 16:10:25 2013
@@ -178,4 +178,13 @@ namespace pr14776 {
auto b = X(); // expected-warning {{unused variable 'b'}}
}
+namespace UndefinedInternalStaticMember {
+ namespace {
+ struct X {
+ static const unsigned x = 3;
+ int y[x];
+ };
+ }
+}
+
#endif
More information about the cfe-commits
mailing list