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

2023-11-26 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/73220
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-11-26 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/73220
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-11-25 Thread via cfe-commits

https://github.com/mydeveloperday approved this pull request.


https://github.com/llvm/llvm-project/pull/73220
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-11-24 Thread Owen Pan via cfe-commits


@@ -1171,6 +1171,13 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (FormatTok->is(tok::identifier) &&
+  Tokens->peekNextToken()->is(tok::colon)) {
+nextToken();
+nextToken();
+addUnwrappedLine();

owenca wrote:

Good catch!

https://github.com/llvm/llvm-project/pull/73220
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-11-24 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/73220

>From 0a8459053be654313efff8002ff3e171d8cd9d18 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 23 Nov 2023 00:41:41 -0800
Subject: [PATCH 1/2] [clang-format] Fix a bug in formating `#define A x:`

Fixed #70789.
---
 clang/lib/Format/UnwrappedLineParser.cpp | 7 +++
 clang/unittests/Format/FormatTest.cpp| 2 ++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c870ff01605e725..0f841e0bee50b6c 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1171,6 +1171,13 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (FormatTok->is(tok::identifier) &&
+  Tokens->peekNextToken()->is(tok::colon)) {
+nextToken();
+nextToken();
+addUnwrappedLine();
+  }
+
   // 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) {

>From f42867e3129cb31568c5a69b89da9d927554f3fb Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 24 Nov 2023 16:55:11 -0800
Subject: [PATCH 2/2] Removed the unneeded addUnwrappedLine() call.

---
 clang/lib/Format/UnwrappedLineParser.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 0f841e0bee50b6c..7b4ec25a8938fc0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1175,7 +1175,6 @@ void UnwrappedLineParser::parsePPDefine() {
   Tokens->peekNextToken()->is(tok::colon)) {
 nextToken();
 nextToken();
-addUnwrappedLine();
   }
 
   // Errors during a preprocessor directive can only affect the layout of the

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-11-23 Thread Björn Schäpers via cfe-commits


@@ -1171,6 +1171,13 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (FormatTok->is(tok::identifier) &&
+  Tokens->peekNextToken()->is(tok::colon)) {
+nextToken();
+nextToken();
+addUnwrappedLine();

HazardyKnusperkeks wrote:

Why that new line?

https://github.com/llvm/llvm-project/pull/73220
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixed #70789.

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


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+7) 
- (modified) clang/unittests/Format/FormatTest.cpp (+2) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c870ff01605e725..0f841e0bee50b6c 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1171,6 +1171,13 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (FormatTok->is(tok::identifier) &&
+  Tokens->peekNextToken()->is(tok::colon)) {
+nextToken();
+nextToken();
+addUnwrappedLine();
+  }
+
   // 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) {

``




https://github.com/llvm/llvm-project/pull/73220
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-11-23 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/73220

Fixed #70789.

>From 0a8459053be654313efff8002ff3e171d8cd9d18 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 23 Nov 2023 00:41:41 -0800
Subject: [PATCH] [clang-format] Fix a bug in formating `#define A x:`

Fixed #70789.
---
 clang/lib/Format/UnwrappedLineParser.cpp | 7 +++
 clang/unittests/Format/FormatTest.cpp| 2 ++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c870ff01605e725..0f841e0bee50b6c 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1171,6 +1171,13 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (FormatTok->is(tok::identifier) &&
+  Tokens->peekNextToken()->is(tok::colon)) {
+nextToken();
+nextToken();
+addUnwrappedLine();
+  }
+
   // 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) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits