[clang] [clang-format] Fix a crash on triple-bracket input like `[[[a]]` (PR #199103)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 5 05:39:33 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 6f1ef8e03..810d9e68a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -88,9 +88,9 @@ static bool isCppAttribute(bool IsCpp, const FormatToken &Tok) {
if (!IsCpp || !Tok.startsSequence(tok::l_square, tok::l_square))
return false;
// The first square bracket is part of an ObjC array literal
-if (Tok.Previous && Tok.Previous->isOneOf(tok::at, tok::l_square))
-return false;
+ if (Tok.Previous && Tok.Previous->isOneOf(tok::at, tok::l_square))
return false;
+ return false;
const FormatToken *AttrTok = Tok.Next->Next;
if (!AttrTok)
return false;
``````````
</details>
https://github.com/llvm/llvm-project/pull/199103
More information about the cfe-commits
mailing list