[PATCH] D132911: [clang-format] Fix annotating when deleting array of pointers

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 11:00:12 PDT 2022


MyDeveloperDay accepted this revision.
MyDeveloperDay added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:2381-2385
     if (PrevToken->Tok.isLiteral() ||
         PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
                            tok::kw_false, tok::r_brace)) {
       return TT_BinaryOperator;
     }
----------------
jackhong12 wrote:
> The `*` token in `delete *x;` will be annotated as UnaryOperator (dereferencing a pointer). 
> 
> In the case `delete[] *x;`, there is a `]` before `*`. So, it will be annotated as BinaryOperator by this rule.
> 
> I think both `*` here should be UnaryOperator. Therefore, I add a new rule to match the `delete[]` pattern.
 `it will be annotated as BinaryOperator by this rule.` of course my bad


================
Comment at: clang/unittests/Format/FormatTest.cpp:10541
+  verifyFormat("delete[] **ptr;", Style);
+  verifyFormat("delete[] *(ptr);", Style);
+
----------------
could you cover the other PointerAlignment case for completeness


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132911/new/

https://reviews.llvm.org/D132911



More information about the cfe-commits mailing list