[clang-format] throws an incorrect assertion in consumeToken() formatting the MSVC stl
authorPaul Hoad <mydeveloperday@gmail.com>
Thu, 10 Oct 2019 17:54:47 +0000 (17:54 +0000)
committerPaul Hoad <mydeveloperday@gmail.com>
Thu, 10 Oct 2019 17:54:47 +0000 (17:54 +0000)
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

llvm-svn: 374399

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index 88f7468..9823a5a 100644 (file)
@@ -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();
index dde065a..b0d7f08 100644 (file)
@@ -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