diff options
author | Marek Kurdej <marek.kurdej+llvm.org@gmail.com> | 2022-01-14 21:51:06 +0100 |
---|---|---|
committer | Marek Kurdej <marek.kurdej+llvm.org@gmail.com> | 2022-01-14 21:57:02 +0100 |
commit | 7af11989be21df00ad6a510a831ea2425e48fa90 (patch) | |
tree | e2a08f42bd98f3e9e84e861797700052f79fbb7c /clang/unittests/Format/FormatTestJava.cpp | |
parent | e0841f692017cad1edf866e9c6907bffda5ea02c (diff) | |
download | llvm-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.cpp | 11 |
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 |