[cfe-commits] r60858 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Scope.h lib/Parse/ParseStmt.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp test/SemaCXX/warn-for-var-in-else.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Thu Dec 11 06:06:45 PST 2008


Douglas Gregor wrote:
> Author: dgregor
> Date: Wed Dec 10 17:01:14 2008
> New Revision: 60858
>
> URL: http://llvm.org/viewvc/llvm-project?rev=60858&view=rev
> Log:
> Added a warning when referencing an if's condition variable in the
> "else" clause, e.g.,
>
>   if (int X = foo()) {
>   } else {
>     if (X) { // warning: X is always zero in this context
>     }
>   }
>   
What happens for

struct WithToBool
{
  operator bool() { ... }

  // Other data, not necessarily invalid if (bool)WTB is false.
};

if(WithToBool wtb = something()) {
} else {
  orother(wtb);
}

It seems to me, from looking at the code (not trying it) that this will 
warn about wtb always being zero.

Sebastian




More information about the cfe-commits mailing list