From 7af11989be21df00ad6a510a831ea2425e48fa90 Mon Sep 17 00:00:00 2001 From: Marek Kurdej Date: Fri, 14 Jan 2022 21:51:06 +0100 Subject: [clang-format] Fix short functions being considered as inline inside an indented namespace. Fixes https://github.com/llvm/llvm-project/issues/24784. With config: ``` AllowShortFunctionsOnASingleLine: Inline NamespaceIndentation: All ``` The code: ``` namespace Test { void f() { return; } } ``` was incorrectly formatted to: ``` namespace Test { void f() { return; } } ``` since the function `f` was considered being inside a class/struct/record. That's because the check was simplistic and only checked for a non-zero indentation level of the line starting `f`. Reviewed By: MyDeveloperDay, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D117142 --- clang/unittests/Format/FormatTestJava.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'clang/unittests/Format/FormatTestJava.cpp') diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 84f6420..e778836e 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -602,5 +602,16 @@ TEST_F(FormatTestJava, RetainsLogicalShifts) { "}"); } +TEST_F(FormatTestJava, ShortFunctions) { + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Java); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + verifyFormat("enum Enum {\n" + " E1,\n" + " E2;\n" + " void f() { return; }\n" + "}", + Style); +} + } // namespace format } // end namespace clang -- cgit v1.1