clang-format: Add support for SEH __try / __except / __finally blocks.
This lets clang-format format
__try {
} __except(0) {
}
and
__try {
} __finally {
}
correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set,
so this turns this on. This also enables a few other keywords, but it
shouldn't overly perturb regular clang-format operation. __except is a
context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to
a few more places.
Fixes PR22321.
llvm-svn: 228148
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f099f20..b88bdb9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2244,6 +2244,26 @@
verifyFormat("try {} catch (");
}
+TEST_F(FormatTest, FormatSEHTryCatch) {
+ verifyFormat("__try {\n"
+ " int a = b * c;\n"
+ "} __except (EXCEPTION_EXECUTE_HANDLER) {\n"
+ " // Do nothing.\n"
+ "}");
+
+ verifyFormat("__try {\n"
+ " int a = b * c;\n"
+ "} __finally {\n"
+ " // Do nothing.\n"
+ "}");
+
+ verifyFormat("DEBUG({\n"
+ " __try {\n"
+ " } __finally {\n"
+ " }\n"
+ "});\n");
+}
+
TEST_F(FormatTest, IncompleteTryCatchBlocks) {
verifyFormat("try {\n"
" f();\n"
@@ -2276,6 +2296,13 @@
" // something\n"
"}",
Style);
+ verifyFormat("__try {\n"
+ " // something\n"
+ "}\n"
+ "__finally {\n"
+ " // something\n"
+ "}",
+ Style);
Style.BreakBeforeBraces = FormatStyle::BS_Allman;
verifyFormat("try\n"
"{\n"