[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning
eric via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 3 10:02:22 PDT 2018
Higuoxing created this revision.
Herald added a subscriber: cfe-commits.
Higuoxing edited the summary of this revision.
Hi,
As you see, to avoid some expression like
assert(x || y && "some messages");
clang will skip all the parentheses check if the expression is in `macro`;
and this rule is a little bit loose, if a function which takes boolean variables defined in `macros`,
clang will not check parentheses for these functions;
So, in this patch I add a string type checking, if and only if a function defined in macro and the RHS of boolean expression is a string, then skip the parentheses checking :)
Thanks for reviewing :)
Repository:
rC Clang
https://reviews.llvm.org/D47687
Files:
lib/Sema/SemaExpr.cpp
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12310,7 +12310,14 @@
// Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
// We don't warn for 'assert(a || b && "bad")' since this is safe.
- if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
+ StringLiteral* diagnoseRHSToBeString
+ = dyn_cast<StringLiteral>(RHSExpr->IgnoreImpCasts());
+ if (Opc == BO_LOr &&
+ !(OpLoc.isMacroID() &&
+ diagnoseRHSToBeString)
+ /* Don't warn in macros,
+ if and only if RHS could be
+ evaluated as string */) {
DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47687.149648.patch
Type: text/x-patch
Size: 806 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180603/a5a8508c/attachment-0001.bin>
More information about the cfe-commits
mailing list