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) {
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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits