[llvm-branch-commits] [clang] b9ceb93 - Revert "[clang-format] Don't count template template parameter as declaration…"
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Jun 22 05:18:34 PDT 2024
Author: Mehdi Amini
Date: 2024-06-22T14:18:31+02:00
New Revision: b9ceb93bc8d7fe75365f0d9002ed8b48a0884c85
URL: https://github.com/llvm/llvm-project/commit/b9ceb93bc8d7fe75365f0d9002ed8b48a0884c85
DIFF: https://github.com/llvm/llvm-project/commit/b9ceb93bc8d7fe75365f0d9002ed8b48a0884c85.diff
LOG: Revert "[clang-format] Don't count template template parameter as declaration…"
This reverts commit 4a7bf42a9b83144db8a11ac06cce4da21166e6a2.
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 89e134144d433..55c5ecee45e0c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -127,7 +127,7 @@ class AnnotatingParser {
SmallVector<ScopeType> &Scopes)
: Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)),
- Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
+ Keywords(Keywords), Scopes(Scopes) {
assert(IsCpp == LangOpts.CXXOperatorNames);
Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
resetTokenMetadata();
@@ -1266,22 +1266,16 @@ class AnnotatingParser {
}
bool parseTemplateDeclaration() {
- if (!CurrentToken || CurrentToken->isNot(tok::less))
- return false;
-
- CurrentToken->setType(TT_TemplateOpener);
- next();
-
- TemplateDeclarationDepth++;
- const bool WellFormed = parseAngle();
- TemplateDeclarationDepth--;
- if (!WellFormed)
- return false;
-
- if (CurrentToken && TemplateDeclarationDepth == 0)
- CurrentToken->Previous->ClosesTemplateDeclaration = true;
-
- return true;
+ if (CurrentToken && CurrentToken->is(tok::less)) {
+ CurrentToken->setType(TT_TemplateOpener);
+ next();
+ if (!parseAngle())
+ return false;
+ if (CurrentToken)
+ CurrentToken->Previous->ClosesTemplateDeclaration = true;
+ return true;
+ }
+ return false;
}
bool consumeToken() {
@@ -3097,8 +3091,6 @@ class AnnotatingParser {
// same decision irrespective of the decisions for tokens leading up to it.
// Store this information to prevent this from causing exponential runtime.
llvm::SmallPtrSet<FormatToken *, 16> NonTemplateLess;
-
- int TemplateDeclarationDepth;
};
static const int PrecedenceUnaryOperator = prec::PointerToMember + 1;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index d3b310fe59527..12c4b7fdd5ac2 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -584,23 +584,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) {
EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator);
}
-TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) {
- auto Tokens = annotate("template <template <typename...> typename X,\n"
- " template <typename...> class Y,\n"
- " typename... T>\n"
- "class A {};");
- ASSERT_EQ(Tokens.size(), 28u) << Tokens;
- EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener);
- EXPECT_TOKEN(Tokens[3], tok::less, TT_TemplateOpener);
- EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
- EXPECT_FALSE(Tokens[6]->ClosesTemplateDeclaration);
- EXPECT_TOKEN(Tokens[11], tok::less, TT_TemplateOpener);
- EXPECT_TOKEN(Tokens[14], tok::greater, TT_TemplateCloser);
- EXPECT_FALSE(Tokens[14]->ClosesTemplateDeclaration);
- EXPECT_TOKEN(Tokens[21], tok::greater, TT_TemplateCloser);
- EXPECT_TRUE(Tokens[21]->ClosesTemplateDeclaration);
-}
-
TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
FormatStyle Style = getLLVMStyle();
Style.WhitespaceSensitiveMacros.push_back("FOO");
More information about the llvm-branch-commits
mailing list