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

            Bug ID: 45614
           Summary: clang-format incorrectly indents [[nodiscard]]
                    attribute funtions after a macro without semicolon
           Product: clang
           Version: 9.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

clang-format incorrectly indents [[nodiscard]] functions (or any functions with
a [[attribute]]) that follow a macro without a trailing semicolon. This problem
does not affect __attribute__((warn_unused_result)) functions.


```
#define MACRO

MACRO;

__attribute__((warn_unused_result)) int f1(); // ok

MACRO;

[[nodiscard]] int f2(); // ok

MACRO

__attribute__((warn_unused_result)) int f3(); // ok

MACRO

[[nodiscard]] int f4(); // bad: unexpectedly indented!

MACRO

[[bogus_attribute_name]] int f5(); // bad: unexpectedly indented!
```

produces this output:

```
#define MACRO

MACRO;

__attribute__((warn_unused_result)) int f1(); // ok

MACRO;

[[nodiscard]] int f2(); // ok

MACRO

__attribute__((warn_unused_result)) int f3(); // ok

MACRO

    [[nodiscard]] int
    f4(); // bad: unexpectedly indented!

MACRO

    [[bogus_attribute_name]] int
    f5(); // bad: unexpectedly indented!
```

I found this bug when trying to replace __attribute__((warn_unused_result))
with [[nodiscard]] in Firefox source code:
https://bugzilla.mozilla.org/show_bug.cgi?id=1629756. I am testing clang-format
version 9.0.1.

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

Reply via email to