From 91b9e6729c11cce8cf5fea727c6cb81ab8ab5ba4 Mon Sep 17 00:00:00 2001 From: Marek Kurdej Date: Fri, 7 Jan 2022 10:02:45 +0100 Subject: [clang-format] Fix `BraceWrapping: AfterFunction` affecting synchronized blocks in Java. Fixes https://github.com/llvm/llvm-project/issues/32031. Before this change, BraceWrapping: AfterFunction would affect synchronized blocks in Java, but they should be formatted w.r.t. BraceWrapping: AfterControlStatement. Using the config: ``` BreakBeforeBraces: Custom BraceWrapping: AfterControlStatement: false AfterFunction: true ``` would result in misformatted code like: ``` class Foo { void bar() { synchronized (this) { a(); a(); } } } ``` instead of: ``` class Foo { void bar() { synchronized (this) { a(); a(); } } } ``` Reviewed By: MyDeveloperDay, owenpan Differential Revision: https://reviews.llvm.org/D116767 --- clang/unittests/Format/FormatTestJava.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'clang/unittests/Format/FormatTestJava.cpp') diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 9a18c28..84f6420 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -431,6 +431,24 @@ TEST_F(FormatTestJava, SynchronizedKeyword) { verifyFormat("synchronized (mData) {\n" " // ...\n" "}"); + + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Java); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + + Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always; + Style.BraceWrapping.AfterFunction = false; + verifyFormat("synchronized (mData)\n" + "{\n" + " // ...\n" + "}", + Style); + + Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Never; + Style.BraceWrapping.AfterFunction = true; + verifyFormat("synchronized (mData) {\n" + " // ...\n" + "}", + Style); } TEST_F(FormatTestJava, AssertKeyword) { -- cgit v1.1