Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/19.x: [clang-format] Handle template closer followed by braces (#110971) #111958

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

llvmbot
Copy link
Collaborator

@llvmbot llvmbot commented Oct 11, 2024

Backport e5b05a5

Requested by: @owenca

@llvmbot llvmbot added this to the LLVM 19.X Release milestone Oct 11, 2024
@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 11, 2024

@mydeveloperday What do you think about merging this PR to the release branch?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 11, 2024

@llvm/pr-subscribers-clang-format

Author: None (llvmbot)

Changes

Backport e5b05a5

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 --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

@owenca owenca added the regression:19 Regression in 19 release label Oct 11, 2024
@tru tru merged commit 96839b6 into llvm:release/19.x Oct 15, 2024
8 of 10 checks passed
Copy link

@owenca (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format regression:19 Regression in 19 release
Projects
Development

Successfully merging this pull request may close these issues.

4 participants