[llvm-branch-commits] [clang] 587b3b2 - [clang-format] Expand the SpacesAroundConditions option to include catch statements

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 21 09:55:58 PST 2020


Author: mydeveloperday
Date: 2020-01-21T18:53:05+01:00
New Revision: 587b3b2a13d27c50006607a6b7e7458e6d7cc3fa

URL: https://github.com/llvm/llvm-project/commit/587b3b2a13d27c50006607a6b7e7458e6d7cc3fa
DIFF: https://github.com/llvm/llvm-project/commit/587b3b2a13d27c50006607a6b7e7458e6d7cc3fa.diff

LOG: [clang-format] Expand the SpacesAroundConditions option to include catch statements

Summary: This diff expands the SpacesAroundConditions option added in D68346 to include adding spaces to catch statements.

Reviewed By: MyDeveloperDay

Patch by: timwoj

Differential Revision: https://reviews.llvm.org/D72793

(cherry picked from commit ea2be452542c81b04621e26c0d5e83be565f07e2)

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index d5d394e61926..88564e02f23e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2596,7 +2596,7 @@ bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
 /// 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,

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2d67b9759d7f..c47e2e9a116e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14927,6 +14927,7 @@ TEST_F(FormatTest, SpacesInConditionalStatement) {
   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);


        


More information about the llvm-branch-commits mailing list