[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-04-25 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-04-23 Thread via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-03-11 Thread Ilya Biryukov via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

ilya-biryukov wrote:

Adding a space makes total sense in code that **has an argument** to `not`.
But this case seems special because `V(not!)` or `V(not)` clearly can't be a 
full expression by themselves. So it feels preferable to not add any extra 
spaces.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-03-11 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

I just wanted to bring up that using `WhitespaceSensitiveMacros` here is a 
little tricky because the macro name one would need to put there is `V` (the 
name is taken directly from the code that hit this).
Having a more sophisticated option to say "parameter `V` of macro 
`MyComplicatedMacro` is a string-sensitive macro" should work better, but seems 
like an overkill. 

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

zygoloid wrote:

Another data point: the [Python style 
guide](https://peps.python.org/pep-0008/#other-recommendations) also recommends 
always putting a space after `not`.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Richard Smith via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

zygoloid wrote:

For `not!`, I think adding a space is the right choice for a C++ code 
formatter: `not !b` should probably be formatted with a space, not as `not!b`, 
even though it's a pretty strange thing to write.

I wonder if this should instead be:
```suggestion
if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::comma)) {
```
... with the `)` and `,` cases firing only in places where we can locally tell 
this isn't actually a `not` operator at all.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread Owen Pan via cfe-commits


@@ -24160,6 +24160,14 @@ TEST_F(FormatTest, AlternativeOperators) {
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
 
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");

owenca wrote:

You're right!

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-02-04 Thread via cfe-commits


@@ -24160,6 +24160,14 @@ TEST_F(FormatTest, AlternativeOperators) {
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
 
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");

mydeveloperday wrote:

I've seen this used extensively, I'm not sure it triggers a compile warning.

assert(!"fail")  

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-22 Thread Owen Pan via cfe-commits


@@ -4842,19 +4842,19 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (Right.isOneOf(tok::identifier, tok::numeric_constant)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.
   if (Left.is(tok::exclaim) && Left.TokenText == "not")
 return true;
   if (Left.is(tok::tilde) && Left.TokenText == "compl")
 return true;
-  // Lambda captures allow for a lone &, so "&]" needs to be properly
-  // handled.
-  if (Left.is(tok::amp) && Right.is(tok::r_square))
-return Style.SpacesInSquareBrackets;
 }
+// Lambda captures allow for a lone &, so "&]" needs to be properly
+// handled.
+if (Left.is(tok::amp) && Right.is(tok::r_square))
+  return Style.SpacesInSquareBrackets;
 return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
Right.is(TT_BinaryOperator);

owenca wrote:

```suggestion
return Style.SpaceAfterLogicalNot && Left.is(tok::exclaim);
```
Would this suffice?

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-22 Thread Owen Pan via cfe-commits


@@ -24160,6 +24160,14 @@ TEST_F(FormatTest, AlternativeOperators) {
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
 
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");

owenca wrote:

We should drop  them as they are invalid code (i.e. trigger compiler warnings).

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-22 Thread Owen Pan via cfe-commits


@@ -4842,19 +4842,19 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (Right.isOneOf(tok::identifier, tok::numeric_constant)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.

owenca wrote:

The comment needs to be updated.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-16 Thread via cfe-commits

https://github.com/mydeveloperday updated 
https://github.com/llvm/llvm-project/pull/78176

>From 9d29ad06ff71b855a43f57b339990e41f206ac8d Mon Sep 17 00:00:00 2001
From: mydeveloperday 
Date: Mon, 15 Jan 2024 15:42:59 +
Subject: [PATCH 1/2] [clang-format] adds a space after not inside macros

No need to add an extract space if merging the characters
doesn't cause a problem, hence ) and ! as well as ( do not
require the extraneous space.
---
 clang/lib/Format/TokenAnnotator.cpp   | 2 +-
 clang/unittests/Format/FormatTest.cpp | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 227aa0b97af6ba4..e45271809e80854 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8f115fb8cbf0fbe..54b8593fb98d424 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24159,6 +24159,8 @@ TEST_F(FormatTest, AlternativeOperators) {
 
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
 
   /* FIXME handle alternate tokens
* https://en.cppreference.com/w/cpp/language/operator_alternative

>From ccea956d6a3ebf619520f1b5097d78bc71f8c065 Mon Sep 17 00:00:00 2001
From: mydeveloperday 
Date: Tue, 16 Jan 2024 08:30:14 +
Subject: [PATCH 2/2] [clang-format] adds a space after not inside macros

No need to add an extract space if merging the characters
doesn't cause a problem, hence ) and ! as well as ( do not
require the extraneous space.
---
 clang/lib/Format/TokenAnnotator.cpp   | 10 +-
 clang/unittests/Format/FormatTest.cpp |  6 ++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e45271809e80854..0eec0195b1c63a9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {
+if (Right.isOneOf(tok::identifier, tok::numeric_constant)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.
@@ -4850,11 +4850,11 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   if (Left.is(tok::tilde) && Left.TokenText == "compl")
 return true;
-  // Lambda captures allow for a lone &, so "&]" needs to be properly
-  // handled.
-  if (Left.is(tok::amp) && Right.is(tok::r_square))
-return Style.SpacesInSquareBrackets;
 }
+// Lambda captures allow for a lone &, so "&]" needs to be properly
+// handled.
+if (Left.is(tok::amp) && Right.is(tok::r_square))
+  return Style.SpacesInSquareBrackets;
 return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
Right.is(TT_BinaryOperator);
   }
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 54b8593fb98d424..5a540672eca2a39 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24159,8 +24159,14 @@ TEST_F(FormatTest, AlternativeOperators) {
 
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
+
   verifyFormat("v(not)");
   verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");
 
   /* FIXME handle alternate tokens
* https://en.cppreference.com/w/cpp/language/operator_alternative

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-16 Thread Owen Pan via cfe-commits

owenca wrote:

This should work:
```
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4402,9 +4402,17 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
   if (Left.Finalized)
 return Right.hasWhitespaceBefore();
 
-  // Never ever merge two words.
-  if (Keywords.isWordLike(Right) && Keywords.isWordLike(Left))
-return true;
+  if (Style.isVerilog()) {
+if (Keywords.isWordLike(Left) && Keywords.isWordLike(Right))
+  return true;
+  } else {
+auto IsWordOrNumber = [](const auto ) {
+  return Tok.Tok.getIdentifierInfo() || Tok.is(tok::numeric_constant);
+};
+// Never ever merge two words/numbers.
+if (IsWordOrNumber(Left) && IsWordOrNumber(Right))
+  return true;
+  }
 
   // Leave a space between * and /* to avoid C4138 `comment end` found outside
   // of comment.
@@ -4842,21 +4850,11 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
-  // The alternative operators for ~ and ! are "compl" and "not".
-  // If they are used instead, we do not want to combine them with
-  // the token to the right, unless that is a left paren.
-  if (Left.is(tok::exclaim) && Left.TokenText == "not")
-return true;
-  if (Left.is(tok::tilde) && Left.TokenText == "compl")
-return true;
-  // Lambda captures allow for a lone &, so "&]" needs to be properly
-  // handled.
-  if (Left.is(tok::amp) && Right.is(tok::r_square))
-return Style.SpacesInSquareBrackets;
-}
-return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
-   Right.is(TT_BinaryOperator);
+// Lambda captures allow for a lone &, so "&]" needs to be properly
+// handled.
+if (Left.is(tok::amp) && Right.is(tok::r_square))
+  return Style.SpacesInSquareBrackets;
+return Style.SpaceAfterLogicalNot && Left.is(tok::exclaim);
   }
 
   // If the next token is a binary operator or a selector name, we have
```

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-16 Thread via cfe-commits

mydeveloperday wrote:

> > I think this is kind of too specific.
> 
> +1.
> 
> > Also I agree with [#78166 
> > (comment)](https://github.com/llvm/llvm-project/issues/78166#issuecomment-1892311219)
> >  that `WhitespaceSensitiveMacros` should be used.
> 
> I don't think we should require that the option be used.

+1 to that too! (even though it works)

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread Owen Pan via cfe-commits

owenca wrote:

> I think this is kind of too specific.

+1.

> Also I agree with [#78166 
> (comment)](https://github.com/llvm/llvm-project/issues/78166#issuecomment-1892311219)
>  that `WhitespaceSensitiveMacros` should be used.

I don't think we should require that the option be used.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread Owen Pan via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

owenca wrote:

> The only exception I see are identifiers and numeric literals (as they will 
> combine the tokens together):
> 
> ```c++
> v(not x)
> v(not 1)
> v(not 123.f)
> ```

+1.

> Should this condition be something like `if (Right.isOneOf(tok::ident, /*... 
> numeric literals*/))`? Or will this cause us to not add spaces in undesired 
> places?
> 
> If we can avoid those spaces for only a limited set of tokens, I would 
> probably limit this to `tok::lparen` and `tok::rparen`, the rest seems much 
> less likely.

We should come up with a more general fix.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

I think this is kind of too specific. Whoever uses `not` will most likely not 
combine it with `!`. Also I agree with 
https://github.com/llvm/llvm-project/issues/78166#issuecomment-1892311219 that 
`WhitespaceSensitiveMacros` should be used.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread Ilya Biryukov via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

ilya-biryukov wrote:

I have used `!` merely as an example, I feel that we should probably not add 
space for almost all tokens:
```cpp
#define str(X) #X
#define v(X) str(foo##X)

char *x = v(not;);
char *y = v(not+);
```

The only exception I see are identifiers and numeric literals (as they will 
combine the tokens together):
```cpp
v(not x)
v(not 1)
v(not 123.f)
```

Should this condition be something like `if (Right.isOneOf(tok::ident, /*... 
numeric literals*/))`?
Or will this cause us to not add spaces in undesired places?

If we can avoid those spaces for only a limited set of tokens, I would probably 
limit this to `tok::lparen` and `tok::rparen`, the rest seems much less likely.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: MyDeveloperDay (mydeveloperday)


Changes

No need to add an extract space if merging the characters doesn't cause a 
problem, hence ) and ! as well as ( do not require the extraneous space.

Fixes #78166 

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


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+1-1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+2) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 227aa0b97af6ba..e45271809e8085 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8f115fb8cbf0fb..54b8593fb98d42 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24159,6 +24159,8 @@ TEST_F(FormatTest, AlternativeOperators) {
 
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
 
   /* FIXME handle alternate tokens
* https://en.cppreference.com/w/cpp/language/operator_alternative

``




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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread via cfe-commits

https://github.com/mydeveloperday created 
https://github.com/llvm/llvm-project/pull/78176

No need to add an extract space if merging the characters doesn't cause a 
problem, hence ) and ! as well as ( do not require the extraneous space.

Fixes #78166 

>From 9d29ad06ff71b855a43f57b339990e41f206ac8d Mon Sep 17 00:00:00 2001
From: mydeveloperday 
Date: Mon, 15 Jan 2024 15:42:59 +
Subject: [PATCH] [clang-format] adds a space after not inside macros

No need to add an extract space if merging the characters
doesn't cause a problem, hence ) and ! as well as ( do not
require the extraneous space.
---
 clang/lib/Format/TokenAnnotator.cpp   | 2 +-
 clang/unittests/Format/FormatTest.cpp | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 227aa0b97af6ba..e45271809e8085 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8f115fb8cbf0fb..54b8593fb98d42 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24159,6 +24159,8 @@ TEST_F(FormatTest, AlternativeOperators) {
 
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
 
   /* FIXME handle alternate tokens
* https://en.cppreference.com/w/cpp/language/operator_alternative

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