https://bugs.llvm.org/show_bug.cgi?id=49491

            Bug ID: 49491
           Summary: clang-format removes newlines and indentation if a
                    block is followed by doctest's TEST_CASE macro
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangb...@nondot.org
          Reporter: egor.suvo...@gmail.com
                CC: djas...@google.com, kli...@google.com,
                    llvm-bugs@lists.llvm.org

Created attachment 24608
  --> https://bugs.llvm.org/attachment.cgi?id=24608&action=edit
The original example demonstrating the formatting issue

The following example:

TEST_CASE("Test 1") {
    #ifndef MY_DEF
    {
        int b = 0;
    }
    #endif
}
TEST_CASE("Test 2") {
}

gets formatted by the default clang-format version 10.0.0 as follows:

TEST_CASE("Test 1"){
#ifndef MY_DEF
    {int b = 0;
}
#endif
}
TEST_CASE("Test 2") {}

Note that block inside the `#ifdef` is ruined.

TEST_CASE is a special macro from https://github.com/onqtam/doctest which
creates and registers a test case with a specific name and body.

If I replace `TEST_CASE("Test 1")` with `void foo()`, the problem persists.
However, any of the following changes make the problem go away:

1. Remove #ifndef
2. Replace `TEST_CASE("Test 2")` with `void bar()`.
3. Add `int x;` on a separate line immediately before `TEST_CASE("Test 2")`

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to