owenca wrote:
@Erich-Reitz you were on the right track. See #95354.
https://github.com/llvm/llvm-project/pull/94776
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/Erich-Reitz closed
https://github.com/llvm/llvm-project/pull/94776
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Erich-Reitz wrote:
> This patch formats
>
> ```
> void f() {
> if (foo)
> bar(); // Comment
> #if BAZ
> baz();
> #endif
> }
> ```
>
> to
>
> ```
> void f() {
> if (foo)
> bar();
> // Comment
> #if BAZ
> baz();
> #endif
> }
> ```
>
> The trailing comment shouldn't be
owenca wrote:
This patch formats
```
void f() {
if (foo)
bar(); // Comment
#if BAZ
baz();
#endif
}
```
to
```
void f() {
if (foo)
bar();
// Comment
#if BAZ
baz();
#endif
}
```
The trailing comment shouldn't be wrapped.
https://github.com/llvm/llvm-project/pull/94776
@@ -796,6 +796,44 @@ TEST_F(FormatTestComments,
ParsesCommentsAdjacentToPPDirectives) {
format("namespace {}\n /* Test */#define A"));
}
+TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) {
+ verifyFormat("void f() {\n"
+
https://github.com/Erich-Reitz updated
https://github.com/llvm/llvm-project/pull/94776
>From 6c910c8b40be79e3d573f6953860f60ebd27b39f Mon Sep 17 00:00:00 2001
From: Erich Reitz
Date: Fri, 7 Jun 2024 13:04:33 -0400
Subject: [PATCH 1/6] delay flushing comments before ifdef after braceless if;
@@ -796,6 +796,24 @@ TEST_F(FormatTestComments,
ParsesCommentsAdjacentToPPDirectives) {
format("namespace {}\n /* Test */#define A"));
}
+
+TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) {
+ EXPECT_EQ("void f() {\n"
@@ -338,6 +338,9 @@ class UnwrappedLineParser {
// `decltype(auto)`.
bool IsDecltypeAutoFunction = false;
+ // Current nesting depth within unbraced codeblocks.
owenca wrote:
```suggestion
// Nesting depth of unbraced body of a control statement.
```
@@ -4811,8 +4813,11 @@ void UnwrappedLineParser::readToken(int LevelDifference)
{
(!Style.isVerilog() ||
Keywords.isVerilogPPDirective(*Tokens->peekNextToken())) &&
FirstNonCommentOnLine) {
- distributeComments(Comments, FormatTok);
-
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/94776
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -796,6 +796,44 @@ TEST_F(FormatTestComments,
ParsesCommentsAdjacentToPPDirectives) {
format("namespace {}\n /* Test */#define A"));
}
+TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) {
+ verifyFormat("void f() {\n"
+
@@ -4828,7 +4833,10 @@ void UnwrappedLineParser::readToken(int LevelDifference)
{
PPBranchLevel > 0) {
Line->Level += PPBranchLevel;
}
- flushComments(isOnNewLine(*FormatTok));
+
+ if (!UnbracedBodyDepth)
owenca wrote:
https://github.com/owenca commented:
What happens if the comment is unindented, with and without an empty line below
it?
https://github.com/llvm/llvm-project/pull/94776
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
@@ -796,6 +796,24 @@ TEST_F(FormatTestComments,
ParsesCommentsAdjacentToPPDirectives) {
format("namespace {}\n /* Test */#define A"));
}
+
+TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) {
+ EXPECT_EQ("void f() {\n"
https://github.com/Erich-Reitz updated
https://github.com/llvm/llvm-project/pull/94776
>From 6c910c8b40be79e3d573f6953860f60ebd27b39f Mon Sep 17 00:00:00 2001
From: Erich Reitz
Date: Fri, 7 Jun 2024 13:04:33 -0400
Subject: [PATCH 1/5] delay flushing comments before ifdef after braceless if;
https://github.com/Erich-Reitz updated
https://github.com/llvm/llvm-project/pull/94776
>From 6c910c8b40be79e3d573f6953860f60ebd27b39f Mon Sep 17 00:00:00 2001
From: Erich Reitz
Date: Fri, 7 Jun 2024 13:04:33 -0400
Subject: [PATCH 1/4] delay flushing comments before ifdef after braceless if;
github-actions[bot] wrote:
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
You can test this locally with the following command:
``bash
git-clang-format --diff 1b58940c88edaad9320bd21eaa7da65f7e791552
d5aca6de9f513ce049c337dc4c17ea32bb2721aa --
@@ -338,6 +338,9 @@ class UnwrappedLineParser {
// `decltype(auto)`.
bool IsDecltypeAutoFunction = false;
+
+ int UnBracedBodyDepth = 0;
HazardyKnusperkeks wrote:
Could you add some documentation?
https://github.com/llvm/llvm-project/pull/94776
@@ -4828,7 +4834,11 @@ void UnwrappedLineParser::readToken(int LevelDifference)
{
PPBranchLevel > 0) {
Line->Level += PPBranchLevel;
}
- flushComments(isOnNewLine(*FormatTok));
+
+ if (!UnBracedBodyDepth) {
HazardyKnusperkeks
@@ -4736,6 +4738,7 @@ void UnwrappedLineParser::distributeComments(
// the two lines about b form a maximal trail, so there are two sections, the
// first one consisting of the single comment "// line about a" and the
// second one consisting of the next two comments.
+
@@ -796,6 +796,24 @@ TEST_F(FormatTestComments,
ParsesCommentsAdjacentToPPDirectives) {
format("namespace {}\n /* Test */#define A"));
}
+
+TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) {
+ EXPECT_EQ("void f() {\n"
llvmbot wrote:
@llvm/pr-subscribers-clang-format
Author: Erich Reitz (Erich-Reitz)
Changes
Addresses issue #45002.
When `readToken()` sees a preprocessor directive, it eagerly flushes the
comments. This changes the behavior if it is within a braceless block.
Keeps behavior of
```
github-actions[bot] wrote:
Thank you for submitting a Pull Request (PR) to the LLVM Project!
This PR will be automatically labeled and the relevant teams will be
notified.
If you wish to, you can add reviewers by using the "Reviewers" section on this
page.
If this is not working for you,
https://github.com/Erich-Reitz created
https://github.com/llvm/llvm-project/pull/94776
Addresses issue #45002.
When `readToken()` sees a preprocessor directive, it eagerly flushes the
comments. This changes the behavior if it is within a braceless block.
Keeps behavior of
```
void f() {
24 matches
Mail list logo