[clang] [clang-format] Insert a space between l_paren and ref-qualifier (PR #111465)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 19:36:39 PDT 2024
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/111465
Fixes #111346.
>From 9d9405d55fbaeea13d80bb394402fee2f0ef34ca Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Mon, 7 Oct 2024 19:34:16 -0700
Subject: [PATCH] [clang-format] Insert a space between l_paren and
ref-qualifier
Fixes #111346.
---
clang/lib/Format/TokenAnnotator.cpp | 4 ++++
clang/unittests/Format/FormatTest.cpp | 1 +
2 files changed, 5 insertions(+)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index f6e5798057bbd2..364d7e9855e8cf 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5454,6 +5454,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
}
if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
return ShouldAddSpacesInAngles();
+ if (Left.is(tok::r_paren) && Right.is(TT_PointerOrReference) &&
+ Right.isOneOf(tok::amp, tok::ampamp)) {
+ return true;
+ }
// Space before TT_StructuredBindingLSquare.
if (Right.is(TT_StructuredBindingLSquare)) {
return !Left.isOneOf(tok::amp, tok::ampamp) ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 61287aafe8273d..2c5e5857445c35 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11519,6 +11519,7 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
AlignLeft);
verifyFormat("template <typename T> void operator=(T) & {}", AlignLeft);
verifyFormat("template <typename T> void operator=(T) && {}", AlignLeft);
+ verifyFormat("for (foo<void() &&>& cb : X)", AlignLeft);
FormatStyle AlignMiddle = getLLVMStyle();
AlignMiddle.PointerAlignment = FormatStyle::PAS_Middle;
More information about the cfe-commits
mailing list