[llvm-branch-commits] [clang] release/19.x: [clang-format] Handle template closer followed by braces (#110971) (PR #111958)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 11 00:12:47 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: None (llvmbot)
<details>
<summary>Changes</summary>
Backport e5b05a51b8151cc7788bbdea4d491e5ccfceedea
Requested by: @<!-- -->owenca
---
Full diff: https://github.com/llvm/llvm-project/pull/111958.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+5)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5)
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index f7b3561f6e0335..631c7c62baac18 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2131,6 +2131,11 @@ void UnwrappedLineParser::parseStructuralElement(
return;
}
break;
+ case tok::greater:
+ nextToken();
+ if (FormatTok->is(tok::l_brace))
+ FormatTok->Previous->setFinalizedType(TT_TemplateCloser);
+ break;
default:
nextToken();
break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2f09b380a87134..6f3ef3b646c619 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3399,6 +3399,11 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
+
+ Tokens = annotate("return std::conditional_t<T::value == U::value, T, U>{};");
+ ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+ EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
+ EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);
}
} // namespace
``````````
</details>
https://github.com/llvm/llvm-project/pull/111958
More information about the llvm-branch-commits
mailing list