Author: paulhoad Date: Thu Oct 10 10:54:47 2019 New Revision: 374399 URL: http://llvm.org/viewvc/llvm-project?rev=374399&view=rev Log: [clang-format] throws an incorrect assertion in consumeToken() formatting the MSVC stl
Summary: An incorrect assertion is thrown when clang-formatting MSVC's STL library ``` Assertion failed: !Line.startsWith(tok::hash), file C:/llvm/llvm-project/clang/lib/Format/TokenAnnotator.cpp, line 847 Stack dump: 0. Program arguments: C:\llvm\build\bin\clang-format.exe -i -n ./stl/inc/xkeycheck.h ``` ``` Enable warning C4005 to find the forbidden define. ``` Reviewers: mitchell-stellar, STL_MSFT, klimek, krasimir Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang-format, #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D68707 Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=374399&r1=374398&r2=374399&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Oct 10 10:54:47 2019 @@ -845,7 +845,6 @@ private: 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(); Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=374399&r1=374398&r2=374399&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Oct 10 10:54:47 2019 @@ -14723,6 +14723,12 @@ TEST_F(FormatTest, NotCastRPaen) { 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits