timwoj created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This diff expands the SpacesAroundConditions option added in D68346 <https://reviews.llvm.org/D68346> to include adding spaces to catch statements. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D72793 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -14927,6 +14927,7 @@ verifyFormat("while ( a )\n return;", Spaces); verifyFormat("while ( (a && b) )\n return;", Spaces); verifyFormat("do {\n} while ( 1 != 0 );", Spaces); + verifyFormat("try {\n} catch ( const std::exception & ) {\n}", Spaces); // Check that space on the left of "::" is inserted as expected at beginning // of condition. verifyFormat("while ( ::func() )\n return;", Spaces); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2596,7 +2596,7 @@ /// otherwise. static bool isKeywordWithCondition(const FormatToken &Tok) { return Tok.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, tok::kw_switch, - tok::kw_constexpr); + tok::kw_constexpr, tok::kw_catch); } bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -14927,6 +14927,7 @@ verifyFormat("while ( a )\n return;", Spaces); verifyFormat("while ( (a && b) )\n return;", Spaces); verifyFormat("do {\n} while ( 1 != 0 );", Spaces); + verifyFormat("try {\n} catch ( const std::exception & ) {\n}", Spaces); // Check that space on the left of "::" is inserted as expected at beginning // of condition. verifyFormat("while ( ::func() )\n return;", Spaces); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2596,7 +2596,7 @@ /// otherwise. static bool isKeywordWithCondition(const FormatToken &Tok) { return Tok.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, tok::kw_switch, - tok::kw_constexpr); + tok::kw_constexpr, tok::kw_catch); } bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits