diff options
author | rayroudc <rayroudc@gmail.com> | 2024-03-27 19:59:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-27 19:59:31 +0100 |
commit | dd06b8e679fd28f51cd065401062041a40b87f9c (patch) | |
tree | 1a56315777b0fc6c32eaefb3713b8694d7244419 /clang/lib/Format/WhitespaceManager.cpp | |
parent | e36ec2f40c7ea998dd11a485b01c32f50b7bf738 (diff) | |
download | llvm-dd06b8e679fd28f51cd065401062041a40b87f9c.zip llvm-dd06b8e679fd28f51cd065401062041a40b87f9c.tar.gz llvm-dd06b8e679fd28f51cd065401062041a40b87f9c.tar.bz2 |
[clang-format] Fix anonymous reference parameter with default value (#86254)
When enabling alignment of consecutive declarations and reference right
alignment, the needed space between `& ` and ` = ` is removed in the
following use case.
Problem (does not compile)
```
int a(const Test &= Test());
double b();
```
Expected:
```
int a(const Test & = Test());
double b();
```
Test command:
```
echo "int a(const Test& = Test()); double b();" | clang-format -style="{AlignConsecutiveDeclarations: true, ReferenceAlignment: Right}"
```
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 710bf8d..d06c42d 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -464,10 +464,11 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End, if (i + 1 != Changes.size()) Changes[i + 1].PreviousEndOfTokenColumn += Shift; - // If PointerAlignment is PAS_Right, keep *s or &s next to the token + // If PointerAlignment is PAS_Right, keep *s or &s next to the token, + // except if the token is equal, then a space is needed. if ((Style.PointerAlignment == FormatStyle::PAS_Right || Style.ReferenceAlignment == FormatStyle::RAS_Right) && - CurrentChange.Spaces != 0) { + CurrentChange.Spaces != 0 && CurrentChange.Tok->isNot(tok::equal)) { const bool ReferenceNotRightAligned = Style.ReferenceAlignment != FormatStyle::RAS_Right && Style.ReferenceAlignment != FormatStyle::RAS_Pointer; |