From: Anders Carlsson Date: Tue, 17 Nov 2009 17:11:23 +0000 (+0000) Subject: Fix PR5531. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58beed91d468863b8c85bce43425422703838d27;p=clang Fix PR5531. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89106 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index d43d58aee9..90b50c61f9 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -814,6 +814,11 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, } return false; } + + case CXXTemporaryObjectExprClass: + case CXXConstructExprClass: + return false; + case ObjCMessageExprClass: return false; @@ -855,15 +860,19 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, Loc = cast(this)->getLParenLoc(); R1 = cast(this)->getSubExpr()->getSourceRange(); return true; - case CXXFunctionalCastExprClass: - // If this is a cast to void, check the operand. Otherwise, the result of - // the cast is unused. - if (getType()->isVoidType()) + case CXXFunctionalCastExprClass: { + const CastExpr *CE = cast(this); + + // If this is a cast to void or a constructor conversion, check the operand. + // Otherwise, the result of the cast is unused. + if (CE->getCastKind() == CastExpr::CK_ToVoid || + CE->getCastKind() == CastExpr::CK_ConstructorConversion) return (cast(this)->getSubExpr() ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); Loc = cast(this)->getTypeBeginLoc(); R1 = cast(this)->getSubExpr()->getSourceRange(); return true; + } case ImplicitCastExprClass: // Check the operand, since implicit casts are inserted by Sema diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp index 704fbe232a..019863686d 100644 --- a/test/SemaCXX/warn-unused-variables.cpp +++ b/test/SemaCXX/warn-unused-variables.cpp @@ -12,3 +12,23 @@ void f() { A a; B b; } + +// PR5531 +namespace PR5531 { + struct A { + }; + + struct B { + B(int); + }; + + struct C { + ~C(); + }; + + void test() { + A(); + B(17); + C(); + } +}