[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-12 Thread Owen Pan via cfe-commits
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

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-12 Thread Erich Reitz via 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

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-12 Thread Erich Reitz via 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

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-09 Thread Owen Pan via cfe-commits
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

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Erich Reitz via cfe-commits
@@ -796,6 +796,44 @@ TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) { format("namespace {}\n /* Test */#define A")); } +TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) { + verifyFormat("void f() {\n" +

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Erich Reitz via cfe-commits
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;

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Owen Pan via cfe-commits
@@ -796,6 +796,24 @@ TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) { format("namespace {}\n /* Test */#define A")); } + +TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) { + EXPECT_EQ("void f() {\n"

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Owen Pan via cfe-commits
@@ -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. ```

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Owen Pan via cfe-commits
@@ -4811,8 +4813,11 @@ void UnwrappedLineParser::readToken(int LevelDifference) { (!Style.isVerilog() || Keywords.isVerilogPPDirective(*Tokens->peekNextToken())) && FirstNonCommentOnLine) { - distributeComments(Comments, FormatTok); -

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Owen Pan via cfe-commits
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

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Owen Pan via cfe-commits
@@ -796,6 +796,44 @@ TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) { format("namespace {}\n /* Test */#define A")); } +TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) { + verifyFormat("void f() {\n" +

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Owen Pan via cfe-commits
@@ -4828,7 +4833,10 @@ void UnwrappedLineParser::readToken(int LevelDifference) { PPBranchLevel > 0) { Line->Level += PPBranchLevel; } - flushComments(isOnNewLine(*FormatTok)); + + if (!UnbracedBodyDepth) owenca wrote:

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-08 Thread Owen Pan via cfe-commits
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

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Erich Reitz via cfe-commits
@@ -796,6 +796,24 @@ TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) { format("namespace {}\n /* Test */#define A")); } + +TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) { + EXPECT_EQ("void f() {\n"

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Erich Reitz via cfe-commits
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;

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Erich Reitz via cfe-commits
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;

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread via cfe-commits
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 --

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Björn Schäpers via cfe-commits
@@ -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

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Björn Schäpers via cfe-commits
@@ -4828,7 +4834,11 @@ void UnwrappedLineParser::readToken(int LevelDifference) { PPBranchLevel > 0) { Line->Level += PPBranchLevel; } - flushComments(isOnNewLine(*FormatTok)); + + if (!UnBracedBodyDepth) { HazardyKnusperkeks

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Björn Schäpers via cfe-commits
@@ -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. +

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Björn Schäpers via cfe-commits
@@ -796,6 +796,24 @@ TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) { format("namespace {}\n /* Test */#define A")); } + +TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) { + EXPECT_EQ("void f() {\n"

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread via cfe-commits
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 ```

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread via cfe-commits
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,

[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)

2024-06-07 Thread Erich Reitz via cfe-commits
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() {