Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -844,14 +844,15 @@ break; case tok::kw_if: case tok::kw_while: - assert(!Line.startsWith(tok::hash)); - if (Tok->is(tok::kw_if) && CurrentToken && - CurrentToken->isOneOf(tok::kw_constexpr, tok::identifier)) - next(); - if (CurrentToken && CurrentToken->is(tok::l_paren)) { - next(); - if (!parseParens(/*LookForDecls=*/true)) - return false; + if (!Line.startsWith(tok::hash)) { + if (Tok->is(tok::kw_if) && CurrentToken && + CurrentToken->isOneOf(tok::kw_constexpr, tok::identifier)) + next(); + if (CurrentToken && CurrentToken->is(tok::l_paren)) { + next(); + if (!parseParens(/*LookForDecls=*/true)) + return false; + } } break; case tok::kw_for: Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -14679,6 +14679,12 @@ */ } -} // end namespace -} // end namespace format -} // end namespace clang +TEST_F(FormatTest, STLWhileNotDefineChed) { + verifyFormat("#if defined(while)\n" + "#define while EMIT WARNING C4005\n" + "#endif // while"); +} + +} // namespace +} // namespace format +} // namespace clang