[PATCH] D117398: [clang-format] Fix bug in parsing `operator<` with template

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 17 09:54:09 PST 2022


curdeius added inline comments.


================
Comment at: clang/lib/Format/FormatTokenLexer.cpp:432
 
+  auto Forth = (Tokens.end() - 4)[0];
   bool FourthTokenIsLess = false;
----------------
MyDeveloperDay wrote:
> isn't this going to crash if Tokens.size() is 3?
It probably will. Anyway, it's a UB. Please do it differently. Also, please fix the typo: "Fourth".


================
Comment at: clang/unittests/Format/FormatTest.cpp:9278
   verifyFormat("operator SomeType<SomeType<int>>();");
+  verifyFormat("operator< <>();");
+  
----------------
Please add a test for a possible crash: something like `verifyFormat("< <>");`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117398



More information about the cfe-commits mailing list