[PATCH] D21134: clang-tidy: new check readability-misplaced-array-index
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 8 08:37:29 PDT 2016
alexfh added a comment.
In https://reviews.llvm.org/D21134#508524, @jroelofs wrote:
> I think the replacement is wrong for something like:
>
> int *arr; int offs1, offs2;
> offs1[arr + offs2] = 42;
>
>
> which I think would give:
>
> int *arr; int offs1, offs2;
> arr + offs2[offs1] = 42;
>
>
> If the precedence of the "indexing" argument is less than that of the subscript operator, then you need to insert parens:
>
> int *arr; int offs1, offs2;
> (arr + offs2)[offs1] = 42;
>
Indeed. It might be relevant to future (current ones seem to be fine) uses of `tooling::fixit::createReplacement` as well, so should probably be taken care of in its implementation. Maybe an additional hint from the calling code is needed (`bool InsertParensIfNeeded = false`).
https://reviews.llvm.org/D21134
More information about the cfe-commits
mailing list