[clang] a369a59 - [clang-format] Fix a bug in formating `#define A x:` (#73220)

via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 26 16:20:24 PST 2023


Author: Owen Pan
Date: 2023-11-26T16:20:19-08:00
New Revision: a369a5946f99254d56455f3deb0031199562c1dd

URL: https://github.com/llvm/llvm-project/commit/a369a5946f99254d56455f3deb0031199562c1dd
DIFF: https://github.com/llvm/llvm-project/commit/a369a5946f99254d56455f3deb0031199562c1dd.diff

LOG: [clang-format] Fix a bug in formating `#define A x:` (#73220)

Fixed #70789.

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index c870ff01605e725..7b4ec25a8938fc0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1171,6 +1171,12 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (FormatTok->is(tok::identifier) &&
+      Tokens->peekNextToken()->is(tok::colon)) {
+    nextToken();
+    nextToken();
+  }
+
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach
   // would be to use the same approach we use on the file level (no

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 67423f9b06fbc37..d095a2b751defe3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1863,6 +1863,8 @@ TEST_F(FormatTest, UnderstandsMacros) {
   verifyFormat("MACRO(something##something)");
   verifyFormat("MACRO(return##something)");
   verifyFormat("MACRO(co_return##something)");
+
+  verifyFormat("#define A x:");
 }
 
 TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {


        


More information about the cfe-commits mailing list