Skip to content

Commit 97dcbde

Browse files
committed
Revert "[clang-format] Handle C++ keywords in other languages better (#132941)"
This reverts commit ab7cee8 which had formatting errors.
1 parent 55ac652 commit 97dcbde

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

clang/lib/Format/FormatTokenLexer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1306,12 +1306,15 @@ FormatToken *FormatTokenLexer::getNextToken() {
13061306
FormatTok->isOneOf(tok::kw_struct, tok::kw_union, tok::kw_delete,
13071307
tok::kw_operator)) {
13081308
FormatTok->Tok.setKind(tok::identifier);
1309+
FormatTok->Tok.setIdentifierInfo(nullptr);
13091310
} else if (Style.isJavaScript() &&
13101311
FormatTok->isOneOf(tok::kw_struct, tok::kw_union,
13111312
tok::kw_operator)) {
13121313
FormatTok->Tok.setKind(tok::identifier);
1314+
FormatTok->Tok.setIdentifierInfo(nullptr);
13131315
} else if (Style.isTableGen() && !Keywords.isTableGenKeyword(*FormatTok)) {
13141316
FormatTok->Tok.setKind(tok::identifier);
1317+
FormatTok->Tok.setIdentifierInfo(nullptr);
13151318
}
13161319
} else if (FormatTok->is(tok::greatergreater)) {
13171320
FormatTok->Tok.setKind(tok::greater);

clang/unittests/Format/FormatTestJS.cpp

+15-27
Original file line numberDiff line numberDiff line change
@@ -828,26 +828,20 @@ TEST_F(FormatTestJS, AsyncFunctions) {
828828
"} ");
829829
// clang-format must not insert breaks between async and function, otherwise
830830
// automatic semicolon insertion may trigger (in particular in a class body).
831-
auto Style = getGoogleJSStyleWithColumns(10);
832831
verifyFormat("async function\n"
833832
"hello(\n"
834833
" myparamnameiswaytooloooong) {\n"
835834
"}",
836835
"async function hello(myparamnameiswaytooloooong) {}",
837-
Style);
838-
verifyFormat("async function\n"
839-
"union(\n"
840-
" myparamnameiswaytooloooong) {\n"
841-
"}",
842-
Style);
836+
getGoogleJSStyleWithColumns(10));
843837
verifyFormat("class C {\n"
844838
" async hello(\n"
845839
" myparamnameiswaytooloooong) {\n"
846840
" }\n"
847841
"}",
848842
"class C {\n"
849843
" async hello(myparamnameiswaytooloooong) {} }",
850-
Style);
844+
getGoogleJSStyleWithColumns(10));
851845
verifyFormat("async function* f() {\n"
852846
" yield fetch(x);\n"
853847
"}");
@@ -1344,16 +1338,15 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
13441338
// The following statements must not wrap, as otherwise the program meaning
13451339
// would change due to automatic semicolon insertion.
13461340
// See http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1.
1347-
auto Style =getGoogleJSStyleWithColumns(10);
1348-
verifyFormat("return aaaaa;", Style);
1349-
verifyFormat("yield aaaaa;", Style);
1350-
verifyFormat("return /* hello! */ aaaaa;", Style);
1351-
verifyFormat("continue aaaaa;", Style);
1352-
verifyFormat("continue /* hello! */ aaaaa;", Style);
1353-
verifyFormat("break aaaaa;", Style);
1354-
verifyFormat("throw aaaaa;", Style);
1355-
verifyFormat("aaaaaaaaa++;", Style);
1356-
verifyFormat("aaaaaaaaa--;", Style);
1341+
verifyFormat("return aaaaa;", getGoogleJSStyleWithColumns(10));
1342+
verifyFormat("yield aaaaa;", getGoogleJSStyleWithColumns(10));
1343+
verifyFormat("return /* hello! */ aaaaa;", getGoogleJSStyleWithColumns(10));
1344+
verifyFormat("continue aaaaa;", getGoogleJSStyleWithColumns(10));
1345+
verifyFormat("continue /* hello! */ aaaaa;", getGoogleJSStyleWithColumns(10));
1346+
verifyFormat("break aaaaa;", getGoogleJSStyleWithColumns(10));
1347+
verifyFormat("throw aaaaa;", getGoogleJSStyleWithColumns(10));
1348+
verifyFormat("aaaaaaaaa++;", getGoogleJSStyleWithColumns(10));
1349+
verifyFormat("aaaaaaaaa--;", getGoogleJSStyleWithColumns(10));
13571350
verifyFormat("return [\n"
13581351
" aaa\n"
13591352
"];",
@@ -1373,13 +1366,12 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
13731366
// Ideally the foo() bit should be indented relative to the async function().
13741367
verifyFormat("async function\n"
13751368
"foo() {}",
1376-
Style);
1377-
verifyFormat("await theReckoning;", Style);
1378-
verifyFormat("some['a']['b']", Style);
1379-
verifyFormat("union['a']['b']", Style);
1369+
getGoogleJSStyleWithColumns(10));
1370+
verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
1371+
verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10));
13801372
verifyFormat("x = (a['a']\n"
13811373
" ['b']);",
1382-
Style);
1374+
getGoogleJSStyleWithColumns(10));
13831375
verifyFormat("function f() {\n"
13841376
" return foo.bar(\n"
13851377
" (param): param is {\n"
@@ -2508,10 +2500,6 @@ TEST_F(FormatTestJS, NonNullAssertionOperator) {
25082500
TEST_F(FormatTestJS, CppKeywords) {
25092501
// Make sure we don't mess stuff up because of C++ keywords.
25102502
verifyFormat("return operator && (aa);");
2511-
verifyFormat("enum operator {\n"
2512-
" A = 1,\n"
2513-
" B\n"
2514-
"}");
25152503
// .. or QT ones.
25162504
verifyFormat("const slots: Slot[];");
25172505
// use the "!" assertion operator to validate that clang-format understands

clang/unittests/Format/FormatTestJava.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ TEST_F(FormatTestJava, AnonymousClasses) {
158158

159159
TEST_F(FormatTestJava, EnumDeclarations) {
160160
verifyFormat("enum SomeThing { ABC, CDE }");
161-
// A C++ keyword should not mess things up.
162-
verifyFormat("enum union { ABC, CDE }");
163161
verifyFormat("enum SomeThing {\n"
164162
" ABC,\n"
165163
" CDE,\n"

0 commit comments

Comments
 (0)