[clang] [clang-format] Fix bug assuming short macro call without semicolon (PR #121626)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 3 22:39:19 PST 2025
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/121626
Fixes #105658.
>From 6c95c2213467ad013406c7b8b9d9ff709a38e047 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Fri, 3 Jan 2025 22:35:38 -0800
Subject: [PATCH] [clang-format] Fix bug assuming short macro call without
semicolon
Fixes #105658.
---
clang/lib/Format/UnwrappedLineParser.cpp | 4 +++-
clang/unittests/Format/FormatTest.cpp | 5 +++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 654148a161bd7f..dd0fb939385369 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2041,7 +2041,9 @@ void UnwrappedLineParser::parseStructuralElement(
? FormatTok->NewlinesBefore > 0
: CommentsBeforeNextToken.front()->NewlinesBefore > 0;
- if (FollowedByNewline && (Text.size() >= 5 || FunctionLike) &&
+ if (FollowedByNewline &&
+ (Text.size() >= 5 ||
+ (FunctionLike && FormatTok->isNot(tok::l_paren))) &&
tokenCanStartNewLine(*FormatTok) && Text == Text.upper()) {
if (PreviousToken->isNot(TT_UntouchableMacroFunc))
PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 44b9dba2498900..4d48bcacddead8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5887,6 +5887,11 @@ TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
verifyFormat("SOME_WEIRD_LOG_MACRO << SomeThing;", "SOME_WEIRD_LOG_MACRO\n"
"<< SomeThing;");
+ verifyFormat("GGGG(ffff(xxxxxxxxxxxxxxxxxxxx)->yyyyyyyyyyyyyyyyyyyy)(foo);",
+ "GGGG(ffff(xxxxxxxxxxxxxxxxxxxx)->yyyyyyyyyyyyyyyyyyyy)\n"
+ "(foo);",
+ getLLVMStyleWithColumns(60));
+
verifyFormat("VISIT_GL_CALL(GenBuffers, void, (GLsizei n, GLuint* buffers), "
"(n, buffers))",
getChromiumStyle(FormatStyle::LK_Cpp));
More information about the cfe-commits
mailing list