Skip to content

Commit a4d4859

Browse files
authored
[clang-format] Fix a bug in DerivePointerAlignment: true (#150387)
Fixes #150327
1 parent 29b9bdf commit a4d4859

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clang/lib/Format/Format.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,13 +2644,14 @@ class Formatter : public TokenAnalyzer {
26442644
for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
26452645
if (Tok->isNot(TT_PointerOrReference))
26462646
continue;
2647-
// Don't treat space in `void foo() &&` as evidence.
2647+
// Don't treat space in `void foo() &&` or `void() &&` as evidence.
26482648
if (const auto *Prev = Tok->getPreviousNonComment()) {
26492649
if (Prev->is(tok::r_paren) && Prev->MatchingParen) {
26502650
if (const auto *Func =
26512651
Prev->MatchingParen->getPreviousNonComment()) {
26522652
if (Func->isOneOf(TT_FunctionDeclarationName, TT_StartOfName,
2653-
TT_OverloadedOperator)) {
2653+
TT_OverloadedOperator) ||
2654+
Func->isTypeName(LangOpts)) {
26542655
continue;
26552656
}
26562657
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12113,6 +12113,8 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
1211312113
Prefix = "void a() const &;\n"
1211412114
"void b() const &;\n";
1211512115
verifyFormat(Prefix + "int *x;", Prefix + "int* x;", DerivePointerAlignment);
12116+
12117+
verifyGoogleFormat("MACRO(int*, std::function<void() &&>);");
1211612118
}
1211712119

1211812120
TEST_F(FormatTest, PointerAlignmentFallback) {

0 commit comments

Comments
 (0)