From 6a1c9d51fa55131ba5964a622355e5e8bbce04c9 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Mon, 2 Oct 2017 15:53:37 +0000 Subject: [clang-format] Fix regression about short functions after #else Summary: This patch fixes a regression introduced in r312904, where the formatter confuses the `else` in `#else` with an `else` of an `if-else` statement. For example, formatting this code with google style ``` #ifdef A int f() {} #else int f() {} #endif ``` resulted in ``` #ifdef A int f() {} #else int f() { } #endif ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D37973 llvm-svn: 314683 --- clang/unittests/Format/FormatTest.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'clang/unittests/Format/FormatTest.cpp') diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8ef11cb3ddc..dadc0254c6d 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -7102,6 +7102,16 @@ TEST_F(FormatTest, SplitEmptyFunction) { "}", Style); } +TEST_F(FormatTest, KeepShortFunctionAfterPPElse) { + FormatStyle Style = getLLVMStyle(); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + verifyFormat("#ifdef A\n" + "int f() {}\n" + "#else\n" + "int g() {}\n" + "#endif", + Style); +} TEST_F(FormatTest, SplitEmptyClass) { FormatStyle Style = getLLVMStyle(); -- cgit v1.2.3