[clang] [clang-tools-extra] [clang-tidy] Address false positives in misc-redundant-expression checker (PR #122841)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 20 07:31:49 PST 2025
================
@@ -847,11 +869,104 @@ static bool areExprsMacroAndNonMacro(const Expr *&LhsExpr,
if (!LhsExpr || !RhsExpr)
return false;
- SourceLocation LhsLoc = LhsExpr->getExprLoc();
- SourceLocation RhsLoc = RhsExpr->getExprLoc();
+ const SourceLocation LhsLoc = LhsExpr->getExprLoc();
+ const SourceLocation RhsLoc = RhsExpr->getExprLoc();
return LhsLoc.isMacroID() != RhsLoc.isMacroID();
}
+
+static bool areStringsSameIgnoreSpaces(const llvm::StringRef *Left,
+ const llvm::StringRef *Right) {
+ if (Left == Right)
+ return true;
+ if (Left->compare(*Right) == 0) {
+ return true;
+ }
+ // Do running index comparison
+ size_t LIdx = 0;
+ size_t RIdx = 0;
+ const char *LData = Left->data();
+ const char *RData = Right->data();
+ while (LIdx < Left->size() && RIdx < Right->size()) {
----------------
PiotrZSL wrote:
write this using ltrim and drop_front, we in 2025, no need to go back to legacy C++
```
Left = Left.trim();
Right = Right.trim();
while(!Left.empty() && !Right.empty()) {
Left = Left.ltrim();
Right = Right.ltrim();
if (Left.front() != Right.front()) return false;
Left = Left.drop_front();
Right = Right.drop_front();
}
return Left.empty() && Right.empty();
```
https://github.com/llvm/llvm-project/pull/122841
More information about the cfe-commits
mailing list