diff options
author | Ted Kremenek <kremenek@apple.com> | 2013-03-15 21:50:10 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2013-03-15 21:50:10 +0000 |
commit | 7adf3a9f84688f334a1cd977317bb42f9e06c9f4 (patch) | |
tree | 9a694bf3657f9dca27924f16b402a19b768a61a6 /lib/Sema/SemaChecking.cpp | |
parent | 2f13eb116e62161c5e4d198f7831f226e5cea9da (diff) |
Enhance -Wtautological-constant-out-of-range-compare to include the name of the enum constant.
This is QoI. Fixes <rdar://problem/13076064>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177190 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index dd797bbdb1..b566488594 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4495,9 +4495,22 @@ static void DiagnoseOutOfRangeComparison(Sema &S, BinaryOperator *E, else // op == BO_GT || op == BO_GE IsTrue = PositiveConstant; } - SmallString<16> PrettySourceValue(Value.toString(10)); + + // If this is a comparison to an enum constant, include that + // constant in the diagnostic. + const EnumConstantDecl *ED = 0; + if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Constant)) + ED = dyn_cast<EnumConstantDecl>(DR->getDecl()); + + SmallString<64> PrettySourceValue; + llvm::raw_svector_ostream OS(PrettySourceValue); + if (ED) + OS << '\'' << ED->getName() << "' (" << Value << ")"; + else + OS << Value; + S.Diag(E->getOperatorLoc(), diag::warn_out_of_range_compare) - << PrettySourceValue << OtherT << IsTrue + << OS.str() << OtherT << IsTrue << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange(); } |