forked from OSchip/llvm-project
[clang-format] Fix misannotation of colon in presence of requires clause
For clauses without parentheses it was annotated as TT_InheritanceColon. Relates to https://github.com/llvm/llvm-project/issues/56215 Differential Revision: https://reviews.llvm.org/D129940
This commit is contained in:
parent
523a99c0eb
commit
2b04c41b28
|
@ -999,7 +999,8 @@ private:
|
|||
FormatToken *Prev = Tok->getPreviousNonComment();
|
||||
if (!Prev)
|
||||
break;
|
||||
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept)) {
|
||||
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
|
||||
Prev->ClosesRequiresClause) {
|
||||
Tok->setType(TT_CtorInitializerColon);
|
||||
} else if (Prev->is(tok::kw_try)) {
|
||||
// Member initializer list within function try block.
|
||||
|
|
|
@ -802,6 +802,70 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
|
|||
<< I;
|
||||
}
|
||||
}
|
||||
|
||||
BaseTokens = annotate("constexpr Foo(Foo const &other)\n"
|
||||
" : value{other.value} {\n"
|
||||
" do_magic();\n"
|
||||
" do_more_magic();\n"
|
||||
"}");
|
||||
|
||||
ConstrainedTokens = annotate("constexpr Foo(Foo const &other)\n"
|
||||
" requires std::is_copy_constructible<T>\n"
|
||||
" : value{other.value} {\n"
|
||||
" do_magic();\n"
|
||||
" do_more_magic();\n"
|
||||
"}");
|
||||
|
||||
NumberOfBaseTokens = 26u;
|
||||
NumberOfAdditionalRequiresClauseTokens = 7u;
|
||||
NumberOfTokensBeforeRequires = 8u;
|
||||
|
||||
ASSERT_EQ(BaseTokens.size(), NumberOfBaseTokens) << BaseTokens;
|
||||
ASSERT_EQ(ConstrainedTokens.size(),
|
||||
NumberOfBaseTokens + NumberOfAdditionalRequiresClauseTokens)
|
||||
<< ConstrainedTokens;
|
||||
|
||||
for (auto I = 0u; I < NumberOfBaseTokens; ++I) {
|
||||
if (I < NumberOfTokensBeforeRequires) {
|
||||
EXPECT_EQ(*BaseTokens[I], *ConstrainedTokens[I]) << I;
|
||||
} else {
|
||||
EXPECT_EQ(*BaseTokens[I],
|
||||
*ConstrainedTokens[I + NumberOfAdditionalRequiresClauseTokens])
|
||||
<< I;
|
||||
}
|
||||
}
|
||||
|
||||
BaseTokens = annotate("constexpr Foo(Foo const &other)\n"
|
||||
" : value{other.value} {\n"
|
||||
" do_magic();\n"
|
||||
" do_more_magic();\n"
|
||||
"}");
|
||||
|
||||
ConstrainedTokens = annotate("constexpr Foo(Foo const &other)\n"
|
||||
" requires (std::is_copy_constructible<T>)\n"
|
||||
" : value{other.value} {\n"
|
||||
" do_magic();\n"
|
||||
" do_more_magic();\n"
|
||||
"}");
|
||||
|
||||
NumberOfBaseTokens = 26u;
|
||||
NumberOfAdditionalRequiresClauseTokens = 9u;
|
||||
NumberOfTokensBeforeRequires = 8u;
|
||||
|
||||
ASSERT_EQ(BaseTokens.size(), NumberOfBaseTokens) << BaseTokens;
|
||||
ASSERT_EQ(ConstrainedTokens.size(),
|
||||
NumberOfBaseTokens + NumberOfAdditionalRequiresClauseTokens)
|
||||
<< ConstrainedTokens;
|
||||
|
||||
for (auto I = 0u; I < NumberOfBaseTokens; ++I) {
|
||||
if (I < NumberOfTokensBeforeRequires) {
|
||||
EXPECT_EQ(*BaseTokens[I], *ConstrainedTokens[I]) << I;
|
||||
} else {
|
||||
EXPECT_EQ(*BaseTokens[I],
|
||||
*ConstrainedTokens[I + NumberOfAdditionalRequiresClauseTokens])
|
||||
<< I;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
|
||||
|
|
Loading…
Reference in New Issue