aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestJava.cpp
diff options
context:
space:
mode:
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-01-14 21:51:06 +0100
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-01-14 21:57:02 +0100
commit7af11989be21df00ad6a510a831ea2425e48fa90 (patch)
treee2a08f42bd98f3e9e84e861797700052f79fbb7c /clang/unittests/Format/FormatTestJava.cpp
parente0841f692017cad1edf866e9c6907bffda5ea02c (diff)
downloadllvm-7af11989be21df00ad6a510a831ea2425e48fa90.zip
llvm-7af11989be21df00ad6a510a831ea2425e48fa90.tar.gz
llvm-7af11989be21df00ad6a510a831ea2425e48fa90.tar.bz2
[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
Diffstat (limited to 'clang/unittests/Format/FormatTestJava.cpp')
-rw-r--r--clang/unittests/Format/FormatTestJava.cpp11
1 files changed, 11 insertions, 0 deletions
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