Skip to content

Conversation

@owenca
Copy link
Contributor

@owenca owenca commented Jul 20, 2024

Fixes #99758.

@llvmbot
Copy link
Member

llvmbot commented Jul 20, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Fixes #99758.


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

2 Files Affected:

  • (modified) clang/lib/Format/TokenAnnotator.cpp (+3-1)
  • (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+14)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index db66911f00f63..06c34bd45eb31 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2625,8 +2625,10 @@ class AnnotatingParser {
       return false;
 
     // int a or auto a.
-    if (PreviousNotConst->isOneOf(tok::identifier, tok::kw_auto))
+    if (PreviousNotConst->isOneOf(tok::identifier, tok::kw_auto) &&
+        PreviousNotConst->isNot(TT_StatementAttributeLikeMacro)) {
       return true;
+    }
 
     // *a or &a or &&a.
     if (PreviousNotConst->is(TT_PointerOrReference))
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index f70424c3ee060..e7bc15d7e1dfa 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2125,6 +2125,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnArrow) {
   ASSERT_EQ(Tokens.size(), 21u) << Tokens;
   EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown);
 
+  auto Style = getLLVMStyle();
+  Style.StatementAttributeLikeMacros.push_back("emit");
+  Tokens = annotate("emit foo()->bar;", Style);
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_StatementAttributeLikeMacro);
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_Unknown);
+
   // Mixed
   Tokens = annotate("auto f() -> int { auto a = b()->c; }");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
@@ -2950,6 +2957,13 @@ TEST_F(TokenAnnotatorTest, StartOfName) {
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::at, TT_ObjCDecl);
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_StartOfName);
+
+  auto Style = getLLVMStyle();
+  Style.StatementAttributeLikeMacros.push_back("emit");
+  Tokens = annotate("emit foo = 0;", Style);
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_StatementAttributeLikeMacro);
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_Unknown);
 }
 
 TEST_F(TokenAnnotatorTest, BraceKind) {

@owenca owenca merged commit dcebe29 into llvm:main Jul 21, 2024
@owenca owenca deleted the 99758 branch July 21, 2024 20:14
winterz pushed a commit to KDAB/GammaRay that referenced this pull request Jul 26, 2024
wait until new clang-format with is released with
llvm/llvm-project#99791
@alex1701c
Copy link

Can we expect this to be backported and released with clang-format-18?

@owenca
Copy link
Contributor Author

owenca commented Sep 14, 2024

Unfortunately no because clang-format is part of llvm, and as far as I know there will be no more llvm 18 point releases.

@alex1701c
Copy link

That is very unfortunate. It means one will either get different results for the clang-format versions, one disables the formatting, or works around it by sth. Like Q_EMIT(something()->mySignal()).

@owenca
Copy link
Contributor Author

owenca commented Sep 15, 2024

That is very unfortunate. It means one will either get different results for the clang-format versions, one disables the formatting, or works around it by sth. Like Q_EMIT(something()->mySignal()).

Or wait for the next release (in this case 19.1.0, which is just around the corner).

@alex1701c
Copy link

But that does not mean everyone who works on the projects will update to that version right away :(

@owenca
Copy link
Contributor Author

owenca commented Sep 19, 2024

Wouldn't you have the same problem if we were to backport the fix, say, to 18.1.9? Anyway, LLVM 19.1.0 has just been released.

@alex1701c
Copy link

I think it would be normal for distros to backport bugfixes. Thus, users should get the new version rather soonish.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clang-format adding spaces around the arrow operator

4 participants