Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-03-14 18:01:24 +0300
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-03-14 18:04:09 +0300
commita6b2f50fb47da3baeee10b1906da6e30ac5d26ec (patch)
tree0b62cd6282eba3c2b90e619cc6447c2150a5a32e /clang
parent3297571e325a73bad615c57ec117a12f190bd6bc (diff)
Revert "[clang-format] Correctly format variable templates."
This reverts commit a140b7104fdae0d9eff5b18efbc784754e0ca274. It provoked the bug https://github.com/llvm/llvm-project/issues/54374.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp24
-rw-r--r--clang/unittests/Format/FormatTest.cpp6
-rw-r--r--clang/unittests/Format/TokenAnnotatorTest.cpp25
3 files changed, 1 insertions, 54 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 6cf3681cdd9d..0c760b5b2811 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1526,30 +1526,8 @@ private:
if (Current.getPrecedence() != prec::Assignment)
return false;
- if (Line.First->isOneOf(tok::kw_using, tok::kw_return))
+ if (Line.First->isOneOf(tok::kw_template, tok::kw_using, tok::kw_return))
return false;
- if (Line.First->is(tok::kw_template)) {
- // `template` keyword can start a variable template.
- const FormatToken *Tok = Line.First->getNextNonComment();
- assert(Tok); // Current token is on the same line.
- if (Tok->isNot(TT_TemplateOpener)) {
- // Explicit template instantiations do not have `<>`.
- return false;
- }
-
- Tok = Tok->MatchingParen;
- if (!Tok)
- return false;
- Tok = Tok->getNextNonComment();
- if (!Tok)
- return false;
-
- if (Tok->isOneOf(tok::kw_class, tok::kw_enum, tok::kw_concept,
- tok::kw_struct, tok::kw_using))
- return false;
-
- return true;
- }
// Type aliases use `type X = ...;` in TypeScript and can be exported
// using `export type ...`.
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index aadd24a0d6ca..05427c624974 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25625,12 +25625,6 @@ TEST_F(FormatTest, AlignArrayOfStructuresRightAlignmentNonSquare) {
Style);
}
-TEST_F(FormatTest, FormatsVariableTemplates) {
- verifyFormat("inline bool var = is_integral_v<int> && is_signed_v<int>;");
- verifyFormat("template <typename T> "
- "inline bool var = is_integral_v<T> && is_signed_v<T>;");
-}
-
} // namespace
} // namespace format
} // namespace clang
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index dd868be99f45..dff8c0466260 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -117,31 +117,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsEnums) {
EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_EnumLBrace);
}
-TEST_F(TokenAnnotatorTest, UnderstandsDefaultedAndDeletedFunctions) {
- auto Tokens = annotate("auto operator<=>(const T &) const & = default;");
- EXPECT_EQ(Tokens.size(), 14u) << Tokens;
- EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);
-
- Tokens = annotate("template <typename T> void F(T) && = delete;");
- EXPECT_EQ(Tokens.size(), 15u) << Tokens;
- EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
-}
-
-TEST_F(TokenAnnotatorTest, UnderstandsVariables) {
- auto Tokens =
- annotate("inline bool var = is_integral_v<int> && is_signed_v<int>;");
- EXPECT_EQ(Tokens.size(), 15u) << Tokens;
- EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_BinaryOperator);
-}
-
-TEST_F(TokenAnnotatorTest, UnderstandsVariableTemplates) {
- auto Tokens =
- annotate("template <typename T> "
- "inline bool var = is_integral_v<int> && is_signed_v<int>;");
- EXPECT_EQ(Tokens.size(), 20u) << Tokens;
- EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
-}
-
TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
auto Tokens = annotate("#define BEGIN NS {");
EXPECT_EQ(Tokens.size(), 6u) << Tokens;