[cfe-commits] r166534 - in /cfe/trunk: lib/AST/Expr.cpp test/Sema/unused-expr.c
Matt Beaumont-Gay
matthewbg at google.com
Tue Oct 23 18:14:28 PDT 2012
Author: matthewbg
Date: Tue Oct 23 20:14:28 2012
New Revision: 166534
URL: http://llvm.org/viewvc/llvm-project?rev=166534&view=rev
Log:
Address feedback from Eli Friedman on r166522.
In particular, we do want to warn on some unused cast subexpressions within
macros.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/Sema/unused-expr.c
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=166534&r1=166533&r2=166534&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Oct 23 20:14:28 2012
@@ -2026,10 +2026,6 @@
}
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 @@
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)
Modified: cfe/trunk/test/Sema/unused-expr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/unused-expr.c?rev=166534&r1=166533&r2=166534&view=diff
==============================================================================
--- cfe/trunk/test/Sema/unused-expr.c (original)
+++ cfe/trunk/test/Sema/unused-expr.c Tue Oct 23 20:14:28 2012
@@ -123,9 +123,13 @@
// 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
More information about the cfe-commits
mailing list