[PATCH] D21134: clang-tidy: new check readability-misplaced-array-index

Jonathan Roelofs via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 8 07:04:42 PDT 2016

jroelofs added a subscriber: jroelofs.
jroelofs added a comment.

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;


More information about the cfe-commits mailing list