diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2010-07-10 12:30:03 +0000 | 
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2010-07-10 12:30:03 +0000 | 
| commit | 17773fcd83ff8d23260d23706a0dd5fd08902b63 (patch) | |
| tree | 562132cb25b4279b14c74cdc3b8e53a5a3ab5432 /clang/lib/Sema/SemaExpr.cpp | |
| parent | d162d85688e33bf69525926410a6614655585936 (diff) | |
| download | bcm5719-llvm-17773fcd83ff8d23260d23706a0dd5fd08902b63.tar.gz bcm5719-llvm-17773fcd83ff8d23260d23706a0dd5fd08902b63.zip | |
Lay the ground work for resoving PR7047. This doesn't actually fix it because
default arguments to template parameters don't have a DeclContext when
instantiated, and so we can't detect that we're in an instantiation context as
opposed to the definition context. However, it fixes the more commonly-occuring
cases in TMP code that use devolve to this type of tautology after
substitution.
llvm-svn: 108044
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 21 | 
1 files changed, 18 insertions, 3 deletions
| diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index a9a3b2c8ce4..b907675b965 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5292,6 +5292,16 @@ QualType Sema::CheckShiftOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,    return LHSTy;  } +static bool IsWithinTemplateSpecialization(Decl *D) { +  if (DeclContext *DC = D->getDeclContext()) { +    if (isa<ClassTemplateSpecializationDecl>(DC)) +      return true; +    if (FunctionDecl *FD = dyn_cast<FunctionDecl>(DC)) +      return FD->isFunctionTemplateSpecialization(); +  } +  return false; +} +  // C99 6.5.8, C++ [expr.rel]  QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,                                      unsigned OpaqueOpc, bool isRelational) { @@ -5310,13 +5320,17 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,      // 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. +    //  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.      Expr *LHSStripped = lex->IgnoreParens();      Expr *RHSStripped = rex->IgnoreParens(); -    if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(LHSStripped)) +    if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(LHSStripped)) {        if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(RHSStripped)) {          if (DRL->getDecl() == DRR->getDecl() && -            !isa<EnumConstantDecl>(DRL->getDecl())) { +            !isa<EnumConstantDecl>(DRL->getDecl()) && +            !IsWithinTemplateSpecialization(DRL->getDecl())) {            DiagRuntimeBehavior(Loc, PDiag(diag::warn_comparison_always)                                << 0 // self-                                << (Opc == BinaryOperator::EQ @@ -5344,6 +5358,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,                                  << always_evals_to);          }        } +    }      if (isa<CastExpr>(LHSStripped))        LHSStripped = LHSStripped->IgnoreParenCasts(); | 

