]> granicus.if.org Git - clang/commitdiff
Fix PR5531.
authorAnders Carlsson <andersca@mac.com>
Tue, 17 Nov 2009 17:11:23 +0000 (17:11 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 17 Nov 2009 17:11:23 +0000 (17:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89106 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/SemaCXX/warn-unused-variables.cpp

index d43d58aee9cefac9f87f4571fa95fe59488c5d0f..90b50c61f989ae40611997d511e79ac45480299c 100644 (file)
@@ -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<CStyleCastExpr>(this)->getLParenLoc();
     R1 = cast<CStyleCastExpr>(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<CastExpr>(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<CastExpr>(this)->getSubExpr()
               ->isUnusedResultAWarning(Loc, R1, R2, Ctx));
     Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc();
     R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange();
     return true;
+  }
 
   case ImplicitCastExprClass:
     // Check the operand, since implicit casts are inserted by Sema
index 704fbe232a8ed04173c8ba63f1d09ef816902efc..019863686d328728c6ea6d3df7c5c8f6398651af 100644 (file)
@@ -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();
+  }
+}