[PATCH] D118969: [clang-format][NFC] Fix a bug in setting type FunctionLBrace
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 4 00:21:47 PST 2022
owenpan updated this revision to Diff 405881.
owenpan added a comment.
Added a test case.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118969/new/
https://reviews.llvm.org/D118969
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -91,6 +91,12 @@
EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_RecordLBrace);
}
+TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
+ auto Tokens = annotate("#define BEGIN NS {");
+ EXPECT_EQ(Tokens.size(), 6u) << Tokens;
+ EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown);
+}
+
} // namespace
} // namespace format
} // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1571,7 +1571,8 @@
} else if (Style.BraceWrapping.AfterFunction) {
addUnwrappedLine();
}
- FormatTok->setType(TT_FunctionLBrace);
+ if (!Line->InPPDirective)
+ FormatTok->setType(TT_FunctionLBrace);
parseBlock();
addUnwrappedLine();
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118969.405881.patch
Type: text/x-patch
Size: 1112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220204/b6a54865/attachment.bin>
More information about the cfe-commits
mailing list