[clang] [clang-format] Handle template closer followed by braces (PR #110971)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 3 01:59:57 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->110968.
---
Full diff: https://github.com/llvm/llvm-project/pull/110971.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 a38a86764d68c5..9c4a065fd93b96 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 de1346b5ddd5a7..27ae7115dbe0e2 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3538,6 +3538,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/110971
More information about the cfe-commits
mailing list