[PATCH] D87291: [clang-format][regression][PR47461] ifdef causes catch to be seen as a function
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 05:23:27 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG40e771c1c0d3: [clang-format][regression][PR47461] ifdef causes catch to be seen as a function (authored by MyDeveloperDay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87291/new/
https://reviews.llvm.org/D87291
Files:
clang/lib/Format/FormatTokenLexer.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2743,6 +2743,43 @@
verifyFormat("int catch, size;");
verifyFormat("catch = foo();");
verifyFormat("if (catch < size) {\n return true;\n}");
+
+ FormatStyle Style = getLLVMStyle();
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterFunction = true;
+ Style.BraceWrapping.BeforeCatch = true;
+ verifyFormat("try {\n"
+ " int bar = 1;\n"
+ "}\n"
+ "catch (...) {\n"
+ " int bar = 1;\n"
+ "}",
+ Style);
+ verifyFormat("#if NO_EX\n"
+ "try\n"
+ "#endif\n"
+ "{\n"
+ "}\n"
+ "#if NO_EX\n"
+ "catch (...) {\n"
+ "}",
+ Style);
+ verifyFormat("try /* abc */ {\n"
+ " int bar = 1;\n"
+ "}\n"
+ "catch (...) {\n"
+ " int bar = 1;\n"
+ "}",
+ Style);
+ verifyFormat("try\n"
+ "// abc\n"
+ "{\n"
+ " int bar = 1;\n"
+ "}\n"
+ "catch (...) {\n"
+ " int bar = 1;\n"
+ "}",
+ Style);
}
TEST_F(FormatTest, FormatSEHTryCatch) {
Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -401,7 +401,7 @@
if (!Try->is(tok::kw_try))
return false;
auto &Next = *(Tokens.end() - 1);
- if (Next->isOneOf(tok::l_brace, tok::colon))
+ if (Next->isOneOf(tok::l_brace, tok::colon, tok::hash, tok::comment))
return false;
if (Tokens.size() > 2) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87291.292466.patch
Type: text/x-patch
Size: 1934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200917/c2e26294/attachment.bin>
More information about the cfe-commits
mailing list