[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
Tue Sep 8 09:07:38 PDT 2020
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: JakeMerdichAMD, krasimir, arichardson, curdeius.
MyDeveloperDay added projects: clang-format, clang.
MyDeveloperDay requested review of this revision.
https://bugs.llvm.org/show_bug.cgi?id=47461
The following change D80940: [clang-format] [PR46159] Linux kernel 'C' code uses 'try' as a variable name, allow clang-format to handle such cases <https://reviews.llvm.org/D80940> caused a regression in code which ifdef's around the try and catch block cause incorrect brace placement around the catch
#ifdef NO_EXCEPTIONS
try
#endif
{
}
#ifdef NO_EXCEPTIONS
catch (...) {
// This is not a small function
bar = 1;
}
#endif
}
The brace after the catch will be placed on a newline
Repository:
rG LLVM Github Monorepo
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,19 @@
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;
+ verifyFormat("#if NO_EX\n"
+ "try\n"
+ "#endif\n"
+ "{\n"
+ "}\n"
+ "#if NO_EX\n"
+ "catch (...) {\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))
return false;
if (Tokens.size() > 2) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87291.290500.patch
Type: text/x-patch
Size: 1229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200908/c10670b4/attachment.bin>
More information about the cfe-commits
mailing list