[PATCH] D68707: [clang-format] throws an incorrect assertion in consumeToken() formatting the MSVC stl
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 08:26:33 PDT 2019
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: mitchell-stellar, STL_MSFT, klimek, krasimir.
MyDeveloperDay added projects: clang-format, clang-tools-extra.
Herald added a project: clang.
MyDeveloperDay edited the summary of this revision.
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
#if defined(while)
#define while EMIT WARNING C4005
#error The C++ Standard Library forbids macroizing the keyword "while". \
Enable warning C4005 to find the forbidden define.
#endif // while
Repository:
rC Clang
https://reviews.llvm.org/D68707
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
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
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68707.224062.patch
Type: text/x-patch
Size: 1556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191009/e193cf96/attachment.bin>
More information about the cfe-commits
mailing list