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