diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 640f03a4ac130..11127daabad55 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1701,7 +1701,8 @@ class AnnotatingParser { break; if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator, tok::comma, tok::arrow) || - Previous->isPointerOrReference() || + (!Previous->isTypeFinalized() && + Previous->isPointerOrReference()) || // User defined literal. Previous->TokenText.starts_with("\"\"")) { Previous->setType(TT_OverloadedOperator); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 4245bd1c58153..624cf67bbb419 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -22318,6 +22318,7 @@ TEST_F(FormatTest, DoNotCrashOnInvalidInput) { verifyNoCrash("#define a\\\n /**/}"); verifyNoCrash(" tst %o5 ! are we doing the gray case?\n" "LY52: ! [internal]"); + verifyNoCrash("operator foo *;"); } TEST_F(FormatTest, FormatsTableGenCode) {