]> granicus.if.org Git - clang/commitdiff
Address feedback from Eli Friedman on r166522.
authorMatt Beaumont-Gay <matthewbg@google.com>
Wed, 24 Oct 2012 01:14:28 +0000 (01:14 +0000)
committerMatt Beaumont-Gay <matthewbg@google.com>
Wed, 24 Oct 2012 01:14:28 +0000 (01:14 +0000)
In particular, we do want to warn on some unused cast subexpressions within
macros.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166534 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/Sema/unused-expr.c

index 68bce4b6f653a1f1ce203aee6f4fce0618bba831..6f4c8e26377fc03679d2e62fd009ccb4b1d3d9f6 100644 (file)
@@ -2026,10 +2026,6 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
   }
   case CXXFunctionalCastExprClass:
   case CStyleCastExprClass: {
-    // Ignore casts within macro expansions.
-    if (getExprLoc().isMacroID())
-      return false;
-
     // Ignore an explicit cast to void unless the operand is a non-trivial
     // volatile lvalue.
     const CastExpr *CE = cast<CastExpr>(this);
@@ -2047,6 +2043,10 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
       return false;
     }
 
+    // Ignore casts within macro expansions.
+    if (getExprLoc().isMacroID())
+      return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+
     // If this is a cast to a constructor conversion, check the operand.
     // Otherwise, the result of the cast is unused.
     if (CE->getCastKind() == CK_ConstructorConversion)
index 6677e48300a59793f1706ad9ef62441bfd76a8a5..aa81febdbbde9f94bc1acf5e70d2b9044b3487eb 100644 (file)
@@ -123,9 +123,13 @@ void f(int i, ...) {
 // PR8371
 int fn5() __attribute__ ((__const));
 
-// OpenSSL has some macros like this.
-#define M(a, b) (long)foo((a), (b))
+// OpenSSL has some macros like this; we shouldn't warn on the cast.
+#define M1(a, b) (long)foo((a), (b))
+// But, we should still warn on other subexpressions of casts in macros.
+#define M2 (long)0;
 void t11(int i, int j) {
-  M(i, j);  // no warning
+  M1(i, j);  // no warning
+  M2;  // expected-warning {{expression result unused}}
 }
-#undef M
+#undef M1
+#undef M2