diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2010-07-12 06:23:38 +0000 | 
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2010-07-12 06:23:38 +0000 | 
| commit | 65a38183f0719df97a6ce2bf6b7cc4b106e60ed9 (patch) | |
| tree | 0e9ac4d03cbc065b1f31781a18298cd11ebdf3bd /clang/lib/Sema/SemaExpr.cpp | |
| parent | c700060e43639b8e92e827a05d8a8eda86b050be (diff) | |
| download | bcm5719-llvm-65a38183f0719df97a6ce2bf6b7cc4b106e60ed9.tar.gz bcm5719-llvm-65a38183f0719df97a6ce2bf6b7cc4b106e60ed9.zip | |
Fix another aspect of PR7047, macro expansions. Previously, this was hacked
around by exempting enums from the check, but this doesn't handle a lot of
cases. A better approach is to directly check if the operator comes from
a macro expansion.
I've removed a reference to the rdar that originally led to the enum
suppression when removing it's overly contrived test case. Let me know if that
number or a more reasilistic test case involving enums is still needed.
llvm-svn: 108128
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 15 | 
1 files changed, 8 insertions, 7 deletions
| diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b907675b965..57b4232294e 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5319,17 +5319,18 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,      // For non-floating point types, check for self-comparisons of the form      // x == x, x != x, x < x, etc.  These always evaluate to a constant, and      // often indicate logic errors in the program. -    // NOTE: Don't warn about comparisons of enum constants. These can arise -    //  from macro expansions, and are usually quite deliberate. Also don't -    //  warn about comparisons which are only self comparisons within -    //  a template specialization. The warnings should catch obvious cases in -    //  the definition of the template anyways. +    // +    // NOTE: Don't warn about comparison expressions resulting from macro +    // expansion. Also don't warn about comparisons which are only self +    // comparisons within a template specialization. The warnings should catch +    // obvious cases in the definition of the template anyways. The idea is to +    // warn when the typed comparison operator will always evaluate to the same +    // result.      Expr *LHSStripped = lex->IgnoreParens();      Expr *RHSStripped = rex->IgnoreParens();      if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(LHSStripped)) {        if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(RHSStripped)) { -        if (DRL->getDecl() == DRR->getDecl() && -            !isa<EnumConstantDecl>(DRL->getDecl()) && +        if (DRL->getDecl() == DRR->getDecl() && !Loc.isMacroID() &&              !IsWithinTemplateSpecialization(DRL->getDecl())) {            DiagRuntimeBehavior(Loc, PDiag(diag::warn_comparison_always)                                << 0 // self- | 

