-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang-format] Handle token-pasted function decl names #142251
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
Conversation
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFix #142178 Full diff: https://github.com/llvm/llvm-project/pull/142251.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index f8272811bbe6c..963b9d2cd7c40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3977,8 +3977,13 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
Tok; Tok = Tok->Next) {
if (Tok->is(TT_StartOfName))
SeenName = true;
- if (Tok->Previous->EndsCppAttributeGroup)
+ const auto *Previous = Tok->Previous;
+ if (Previous->EndsCppAttributeGroup) {
AfterLastAttribute = Tok;
+ } else if (Line.InMacroBody &&
+ Previous->endsSequence(tok::hashhash, TT_StartOfName)) {
+ Tok->setType(TT_StartOfName);
+ }
if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
IsCtorOrDtor ||
isFunctionDeclarationName(LangOpts, *Tok, Line, ClosingParen)) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 1a5ed4b9040c2..ba6a9f813f052 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2257,6 +2257,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
+ Tokens = annotate("#define FUNC(foo, bar) \\\n"
+ " auto foo##bar() -> Type {}");
+ ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+ EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
+ EXPECT_TOKEN(Tokens[12], tok::l_paren, TT_FunctionDeclarationLParen);
+ EXPECT_TOKEN(Tokens[14], tok::arrow, TT_TrailingReturnArrow);
+
Tokens = annotate("int iso_time(time_t);");
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
|
/cherry-pick 29f79ea |
/pull-request #142282 |
@owenca, this introduced multiple regressions (or maybe they are all the same), I do believe. diff --git a/include/petsc/private/hashmap.h b/include/petsc/private/hashmap.h
index c48d69d73ce..265a968a95c 100644
--- a/include/petsc/private/hashmap.h
+++ b/include/petsc/private/hashmap.h
@@ -37,3 +37,3 @@ M*/
#define PETSC_HASH_MAP_DECL(HashT, KeyType, ValType) \
- typedef kh_##HashT##_t *Petsc##HashT; \
+ typedef kh_##HashT##_t *Petsc## HashT; \
static inline PETSC_UNUSED PetscErrorCode Petsc##HashT##Create(Petsc##HashT *); \
diff --git a/include/petsc/private/logimpl.h b/include/petsc/private/logimpl.h
index 6645e51af15..59333efff6a 100644
--- a/include/petsc/private/logimpl.h
+++ b/include/petsc/private/logimpl.h
@@ -13,3 +13,3 @@
#define PETSC_LOG_RESIZABLE_ARRAY(Container, Entry, Key, Constructor, Destructor, Equal) \
- typedef struct _n_PetscLog##Container *PetscLog##Container; \
+ typedef struct _n_PetscLog##Container *PetscLog##Container; \
static inline PETSC_UNUSED PetscErrorCode PetscLog##Container##Create(int, PetscLog##Container *); \
diff --git a/src/dm/impls/plex/plexgmsh.c b/src/dm/impls/plex/plexgmsh.c
index faa5033598d..662c1981f80 100644
--- a/src/dm/impls/plex/plexgmsh.c
+++ b/src/dm/impls/plex/plexgmsh.c
@@ -10,3 +10,3 @@
static int Gmsh_LexOrder_##T##_##p[GmshNumNodes_##T(p)] = {-1}; \
- int *lex = Gmsh_LexOrder_##T##_##p; \
+ int *lex = Gmsh_LexOrder_##T##_##p; \
if (lex[0] == -1) (void)GmshLexOrder_##T(p, lex, 0); \ A reproducer is attached ( |
…)" This reverts commit 29f79ea which caused a regression. See #142251 (comment).
…ames (#142251)" This reverts commit 29f79ea which caused a regression. See llvm/llvm-project#142251 (comment).
I've reverted this patch and sent in another one #142337. |
Fix #142178