diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 13037b6d00604..269cbef272079 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1259,7 +1259,7 @@ class AnnotatingParser { bool parseConditional() { while (CurrentToken) { - if (CurrentToken->is(tok::colon)) { + if (CurrentToken->is(tok::colon) && CurrentToken->is(TT_Unknown)) { CurrentToken->setType(TT_ConditionalExpr); next(); return true; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index cdb68b74ca79f..250e51b542166 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -24393,6 +24393,8 @@ TEST_F(FormatTest, DisableRegions) { TEST_F(FormatTest, DoNotCrashOnInvalidInput) { format("? ) ="); verifyNoCrash("#define a\\\n /**/}"); + verifyNoCrash(" tst %o5 ! are we doing the gray case?\n" + "LY52: ! [internal]"); } TEST_F(FormatTest, FormatsTableGenCode) {