diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -845,7 +845,6 @@ 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(); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -14723,6 +14723,12 @@ verifyFormat("auto operator delete(int &) final"); } -} // 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