[PATCH] D115879: [clang-format] extern with new line brace without indentation
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 16 07:27:22 PST 2021
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: HazardyKnusperkeks, curdeius, owenpan, MarcusJohnson91.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.
https://github.com/llvm/llvm-project/issues/49804
Interaction between IndentExternBlock and AfterExternBlock means you cannot have AfterExternBlock = true and IndentExternBlock = NoIndent/Indent
This patch resolves that
BraceWrapping:
AfterExternBlock: true
IndentExternBlock: AfterExternBlock
Fixes: #49804
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115879
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3811,6 +3811,26 @@
"int foo16();\n"
"}",
Style);
+
+ Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterExternBlock = true;
+ Style.IndentExternBlock = FormatStyle::IEBS_NoIndent;
+ verifyFormat("extern \"C\"\n{ /*13*/\n}", Style);
+ verifyFormat("extern \"C\"\n{\n"
+ "int foo14();\n"
+ "}",
+ Style);
+
+ Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterExternBlock = true;
+ Style.IndentExternBlock = FormatStyle::IEBS_Indent;
+ verifyFormat("extern \"C\"\n{ /*13*/\n}", Style);
+ verifyFormat("extern \"C\"\n{\n"
+ " int foo14();\n"
+ "}",
+ Style);
}
TEST_F(FormatTest, FormatsInlineASM) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1282,10 +1282,10 @@
if (FormatTok->Tok.is(tok::string_literal)) {
nextToken();
if (FormatTok->Tok.is(tok::l_brace)) {
+ if (Style.BraceWrapping.AfterExternBlock) {
+ addUnwrappedLine();
+ }
if (!Style.IndentExternBlock) {
- if (Style.BraceWrapping.AfterExternBlock) {
- addUnwrappedLine();
- }
unsigned AddLevels = Style.BraceWrapping.AfterExternBlock ? 1u : 0u;
parseBlock(/*MustBeDeclaration=*/true, AddLevels);
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115879.394872.patch
Type: text/x-patch
Size: 1871 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211216/4a26d73f/attachment.bin>
More information about the cfe-commits
mailing list