[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 18 12:42:28 PST 2024
Danny =?utf-8?q?Mösch?= <danny.moesch at icloud.com>,
Danny =?utf-8?q?Mösch?= <danny.moesch at icloud.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/82166 at github.com>
================
@@ -706,13 +706,17 @@ void LoopConvertCheck::doConversion(
ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow
? VarNameOrStructuredBinding + "."
: VarNameOrStructuredBinding;
- auto Parents = Context->getParents(*Usage.Expression);
+ const DynTypedNodeList Parents = Context->getParents(*Usage.Expression);
if (Parents.size() == 1) {
if (const auto *Paren = Parents[0].get<ParenExpr>()) {
// Usage.Expression will be replaced with the new index variable,
// and parenthesis around a simple DeclRefExpr can always be
- // removed.
- Range = Paren->getSourceRange();
+ // removed except in case of a `sizeof` operator call.
+ const DynTypedNodeList GrandParents = Context->getParents(*Paren);
+ if (GrandParents.size() != 1 ||
+ !GrandParents[0].get<UnaryExprOrTypeTraitExpr>()) {
----------------
PiotrZSL wrote:
Use `== nullptr`, it's more readable in this case
https://github.com/llvm/llvm-project/pull/82166
More information about the cfe-commits
mailing list