[PATCH] D63369: [AST] Fixed extraneous warnings for binary conditional operator
Nathan Huckleberry via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 14 16:01:04 PDT 2019
Nathan-Huckleberry created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Binary conditional operator gave warnings where ternary operators
did not. They have been fixed to warn similarly to ternary operators.
Link: https://bugs.llvm.org/show_bug.cgi?id=42239
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63369
Files:
clang/lib/AST/Expr.cpp
clang/test/Sema/warn-binary-conditional-expression-unused.c
Index: clang/test/Sema/warn-binary-conditional-expression-unused.c
===================================================================
--- /dev/null
+++ clang/test/Sema/warn-binary-conditional-expression-unused.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s
+int main() {
+ int a;
+ int b;
+ a ? : b; //expected-warning{{expression result unused}}
+ a ? a : b; //expected-warning{{expression result unused}}
+ a ? : ++b;
+ a ? a : ++b;
+ ++a ? : b; //expected-warning{{expression result unused}}
+ ++a ? a : b; //expected-warning{{expression result unused}}
+ ++a ? : ++b;
+ ++a ? a : ++b;
+ return 0;
+};
+
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2352,6 +2352,10 @@
return true;
return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
}
+ case BinaryConditionalOperatorClass: {
+ auto *Exp = cast<BinaryConditionalOperator>(this);
+ return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+ }
case MemberExprClass:
WarnE = this;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63369.204871.patch
Type: text/x-patch
Size: 1180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190614/4c6cfe33/attachment.bin>
More information about the cfe-commits
mailing list