Skip to content

Commit

Permalink
[clang-format] Add regression tests for function ref qualifiers on op…
Browse files Browse the repository at this point in the history
…erator definition. NFC.

Fixes #54374.
  • Loading branch information
mkurdej committed Mar 15, 2022
1 parent 5c4d64e commit e60defb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
24 changes: 24 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9889,6 +9889,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("template <typename T>\n"
"void F(T) && = delete;",
getGoogleStyle());
verifyFormat("template <typename T> void operator=(T) &;");
verifyFormat("template <typename T> void operator=(T) const &;");
verifyFormat("template <typename T> void operator=(T) &noexcept;");
verifyFormat("template <typename T> void operator=(T) & = default;");
verifyFormat("template <typename T> void operator=(T) &&;");
verifyFormat("template <typename T> void operator=(T) && = delete;");
verifyFormat("template <typename T> void operator=(T) & {}");
verifyFormat("template <typename T> void operator=(T) && {}");

FormatStyle AlignLeft = getLLVMStyle();
AlignLeft.PointerAlignment = FormatStyle::PAS_Left;
Expand All @@ -9909,6 +9917,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("void Fn(T const volatile&&) const volatile&&;", AlignLeft);
verifyFormat("void Fn(T const volatile&&) const volatile&& noexcept;",
AlignLeft);
verifyFormat("template <typename T> void operator=(T) &;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) const&;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) & noexcept;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) & = default;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) &&;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) && = delete;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) & {}", AlignLeft);
verifyFormat("template <typename T> void operator=(T) && {}", AlignLeft);

FormatStyle AlignMiddle = getLLVMStyle();
AlignMiddle.PointerAlignment = FormatStyle::PAS_Middle;
Expand All @@ -9930,6 +9946,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("void Fn(T const volatile &&) const volatile &&;", AlignMiddle);
verifyFormat("void Fn(T const volatile &&) const volatile && noexcept;",
AlignMiddle);
verifyFormat("template <typename T> void operator=(T) &;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) const &;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) & noexcept;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) & = default;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) &&;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) && = delete;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) & {}", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) && {}", AlignMiddle);

FormatStyle Spaces = getLLVMStyle();
Spaces.SpacesInCStyleCastParentheses = true;
Expand Down
18 changes: 18 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ TEST_F(TokenAnnotatorTest, UnderstandsDelete) {
EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_CastRParen);
}

TEST_F(TokenAnnotatorTest, UnderstandsFunctionRefQualifiers) {
auto Tokens = annotate("void f() &;");
EXPECT_EQ(Tokens.size(), 7u) << Tokens;
EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);

Tokens = annotate("void operator=() &&;");
EXPECT_EQ(Tokens.size(), 8u) << Tokens;
EXPECT_TOKEN(Tokens[5], tok::ampamp, TT_PointerOrReference);

Tokens = annotate("template <typename T> void f() &;");
EXPECT_EQ(Tokens.size(), 12u) << Tokens;
EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);

Tokens = annotate("template <typename T> void operator=() &;");
EXPECT_EQ(Tokens.size(), 13u) << Tokens;
EXPECT_TOKEN(Tokens[10], tok::amp, TT_PointerOrReference);
}

TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
auto Tokens = annotate("template <typename T>\n"
"concept C = (Foo && Bar) && (Bar && Baz);");
Expand Down

0 comments on commit e60defb

Please sign in to comment.