[clang] [clang-format] Fix a crash on triple-bracket input like `[[[a]]` (PR #199103)

via cfe-commits cfe-commits at lists.llvm.org
Sat May 23 03:11:19 PDT 2026


================
@@ -90,6 +90,12 @@ static bool isCppAttribute(bool IsCpp, const FormatToken &Tok) {
   // The first square bracket is part of an ObjC array literal
   if (Tok.Previous && Tok.Previous->is(tok::at))
     return false;
+  // A C++ attribute specifier '[[...]]' never appears directly inside another
+  // '['. Treating malformed input like '[[[a]]' as one would mis-annotate the
+  // inner '[' as TT_AttributeLSquare while leaving the outer '[' as a raw
+  // tok::l_square, tripping an assertion in canBreakBefore.
+  if (Tok.Previous && Tok.Previous->is(tok::l_square))
----------------
mygitljf wrote:

I don’t think this helps — I’ve verified it.
For `[[[a]]`, the error hits the middle `[` — the loop only runs over `a ] ]` and never finds the `[`, so the `is(tok::l_square)` check in the loop never triggers.

https://github.com/llvm/llvm-project/pull/199103


More information about the cfe-commits mailing list