[llvm-branch-commits] [clang] baeb500 - [clang-format] [PR45357] Fix issue found with operator spacing
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu May 7 11:08:18 PDT 2020
Author: mydeveloperday
Date: 2020-05-07T11:06:57-07:00
New Revision: baeb500a8ca52b144d1bc14a04130964d68eaade
URL: https://github.com/llvm/llvm-project/commit/baeb500a8ca52b144d1bc14a04130964d68eaade
DIFF: https://github.com/llvm/llvm-project/commit/baeb500a8ca52b144d1bc14a04130964d68eaade.diff
LOG: [clang-format] [PR45357] Fix issue found with operator spacing
Summary:
This is a tentative fix for https://bugs.llvm.org/show_bug.cgi?id=45357
Spaces seem to be introduced between * and * due to changes brought in for {D69573}
Reviewers: sylvestre.ledru, mitchell-stellar, sammccall, Abpostelnicu, krasimir, jbcoe
Reviewed By: Abpostelnicu
Subscribers: tstellar, hans, Abpostelnicu, cfe-commits
Tags: #clang, #clang-format
Differential Revision: https://reviews.llvm.org/D78879
(cherry picked from commit b01dca50085768f1f1a5ad21a685906d48c38816)
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 09050cf0bec6..8cb786a4d343 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2176,6 +2176,10 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
Next = Next->Next;
continue;
}
+ if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
+ Next = Next->MatchingParen;
+ continue;
+ }
break;
}
@@ -2705,6 +2709,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
tok::l_square));
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
+ if (Right.is(tok::star) && Left.is(tok::star))
+ return false;
if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
const FormatToken *Previous = &Left;
while (Previous && !Previous->is(tok::kw_operator)) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4d39fa933e86..7f8a3795e6e0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6185,7 +6185,17 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"void\n"
"A::operator[]() {}\n"
"void\n"
- "A::operator!() {}\n",
+ "A::operator!() {}\n"
+ "void\n"
+ "A::operator**() {}\n"
+ "void\n"
+ "A::operator<Foo> *() {}\n"
+ "void\n"
+ "A::operator<Foo> **() {}\n"
+ "void\n"
+ "A::operator<Foo> &() {}\n"
+ "void\n"
+ "A::operator void **() {}\n",
Style);
verifyFormat("constexpr auto\n"
"operator()() const -> reference {}\n"
@@ -6202,6 +6212,10 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"constexpr auto\n"
"operator void *() const -> reference {}\n"
"constexpr auto\n"
+ "operator void **() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator void *() const -> reference {}\n"
+ "constexpr auto\n"
"operator void &() const -> reference {}\n"
"constexpr auto\n"
"operator void &&() const -> reference {}\n"
@@ -14986,9 +15000,20 @@ TEST_F(FormatTest, OperatorSpacing) {
Style.PointerAlignment = FormatStyle::PAS_Right;
verifyFormat("Foo::operator*();", Style);
verifyFormat("Foo::operator void *();", Style);
+ verifyFormat("Foo::operator void **();", Style);
verifyFormat("Foo::operator()(void *);", Style);
verifyFormat("Foo::operator*(void *);", Style);
verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator**();", Style);
+ verifyFormat("Foo::operator&();", Style);
+ verifyFormat("Foo::operator<int> *();", Style);
+ verifyFormat("Foo::operator<Foo> *();", Style);
+ verifyFormat("Foo::operator<int> **();", Style);
+ verifyFormat("Foo::operator<Foo> **();", Style);
+ verifyFormat("Foo::operator<int> &();", Style);
+ verifyFormat("Foo::operator<Foo> &();", Style);
+ verifyFormat("Foo::operator<int> &&();", Style);
+ verifyFormat("Foo::operator<Foo> &&();", Style);
verifyFormat("operator*(int (*)(), class Foo);", Style);
verifyFormat("Foo::operator&();", Style);
@@ -14999,21 +15024,39 @@ TEST_F(FormatTest, OperatorSpacing) {
verifyFormat("operator&(int (&)(), class Foo);", Style);
verifyFormat("Foo::operator&&();", Style);
+ verifyFormat("Foo::operator**();", Style);
verifyFormat("Foo::operator void &&();", Style);
verifyFormat("Foo::operator()(void &&);", Style);
verifyFormat("Foo::operator&&(void &&);", Style);
verifyFormat("Foo::operator&&();", Style);
verifyFormat("operator&&(int(&&)(), class Foo);", Style);
+ verifyFormat("operator const nsTArrayRight<E> &()", Style);
+ verifyFormat("[[nodiscard]] operator const nsTArrayRight<E, Allocator> &()",
+ Style);
+ verifyFormat("operator void **()", Style);
+ verifyFormat("operator const FooRight<Object> &()", Style);
+ verifyFormat("operator const FooRight<Object> *()", Style);
+ verifyFormat("operator const FooRight<Object> **()", Style);
Style.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator**();", Style);
verifyFormat("Foo::operator void*();", Style);
+ verifyFormat("Foo::operator void**();", Style);
verifyFormat("Foo::operator/*comment*/ void*();", Style);
verifyFormat("Foo::operator/*a*/ const /*b*/ void*();", Style);
verifyFormat("Foo::operator/*a*/ volatile /*b*/ void*();", Style);
verifyFormat("Foo::operator()(void*);", Style);
verifyFormat("Foo::operator*(void*);", Style);
verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator<int>*();", Style);
+ verifyFormat("Foo::operator<Foo>*();", Style);
+ verifyFormat("Foo::operator<int>**();", Style);
+ verifyFormat("Foo::operator<Foo>**();", Style);
+ verifyFormat("Foo::operator<int>&();", Style);
+ verifyFormat("Foo::operator<Foo>&();", Style);
+ verifyFormat("Foo::operator<int>&&();", Style);
+ verifyFormat("Foo::operator<Foo>&&();", Style);
verifyFormat("operator*(int (*)(), class Foo);", Style);
verifyFormat("Foo::operator&();", Style);
@@ -15035,9 +15078,17 @@ TEST_F(FormatTest, OperatorSpacing) {
verifyFormat("Foo::operator&&(void&&);", Style);
verifyFormat("Foo::operator&&();", Style);
verifyFormat("operator&&(int(&&)(), class Foo);", Style);
+ verifyFormat("operator const nsTArrayLeft<E>&()", Style);
+ verifyFormat("[[nodiscard]] operator const nsTArrayLeft<E, Allocator>&()",
+ Style);
+ verifyFormat("operator void**()", Style);
+ verifyFormat("operator const FooLeft<Object>&()", Style);
+ verifyFormat("operator const FooLeft<Object>*()", Style);
+ verifyFormat("operator const FooLeft<Object>**()", Style);
// PR45107
verifyFormat("operator Vector<String>&();", Style);
+ verifyFormat("operator const Vector<String>&();", Style);
verifyFormat("operator foo::Bar*();", Style);
verifyFormat("operator const Foo<X>::Bar<Y>*();", Style);
verifyFormat("operator/*a*/ const /*b*/ Foo /*c*/<X> /*d*/ ::Bar<Y>*();",
More information about the llvm-branch-commits
mailing list