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

[clang-format] Correctly identify token-pasted record names #106484

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Aug 29, 2024

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 29, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

See #89706 (comment).


Full diff: https://github.com/llvm/llvm-project/pull/106484.diff

2 Files Affected:

  • (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1)
  • (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+10)
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 93b23d36027a49..5b518bf6c859e8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4029,6 +4029,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
       }
       break;
     case tok::coloncolon:
+    case tok::hashhash:
       break;
     default:
       if (!JSPastExtendsOrImplements && !ClassName &&
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 618ca56eca3696..5aa5d93c1cb067 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3246,6 +3246,16 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_ClassLBrace);
   EXPECT_BRACE_KIND(Tokens[7], BK_Block);
+  EXPECT_TOKEN(Tokens[8], tok::r_brace, TT_ClassRBrace);
+  EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+
+  Tokens = annotate("#define FOO(X) \\\n"
+                    "  struct X##_tag_ {};");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::l_brace, TT_StructLBrace);
+  EXPECT_BRACE_KIND(Tokens[10], BK_Block);
+  EXPECT_TOKEN(Tokens[11], tok::r_brace, TT_StructRBrace);
+  EXPECT_BRACE_KIND(Tokens[11], BK_Block);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {

@owenca owenca added this to the LLVM 19.X Release milestone Aug 29, 2024
Copy link
Member

@kadircet kadircet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@owenca owenca changed the title [clang-format] Correctly identifies token-pasted record names [clang-format] Correctly identify token-pasted record names Aug 29, 2024
@owenca owenca merged commit 7579787 into llvm:main Aug 30, 2024
11 checks passed
@owenca owenca deleted the token-pasting-record-name branch August 30, 2024 02:14
@owenca
Copy link
Contributor Author

owenca commented Aug 30, 2024

/cherry-pick 7579787

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 30, 2024

Failed to cherry-pick: 7579787

https://github.com/llvm/llvm-project/actions/runs/10625680174

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 1, 2024

/pull-request #106900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants