Skip to content

[clang-format] BreakConstructorInitializers doesn't preserve NOLINT comments #41128

@def-

Description

@def-
Bugzilla Link 41783
Version trunk
OS Linux
CC @mydeveloperday

Extended Description

$ cat .clang-format
Language: Cpp
BreakConstructorInitializers: AfterColon
CommentPragmas: 'NOLINT'
$ cat x.cpp
class C
{
public:
C(C&& rhs) : // NOLINT(performance-noexcept-move-constructor)
x(rhs.x),
y(rhs.y)
{}

private:
int x;
int y;
};
$ clang-format x.cpp
class C {
public:
C(C &&rhs) :
// NOLINT(performance-noexcept-move-constructor)
x(rhs.x), y(rhs.y) {}

private:
int x;
int y;
};

After clang-format's reformatting the NOLINT marker loses its meaning for clang-tidy. In this instance a NOLINTNEXTLINE could be used instead as a workaround from clang-tidy's side.

Unfortunately even CommentPragma can't preserve the comment on the same line. The only workaround I found is setting BreakConstructorInitializers: BeforeComma, but in our case this is not wished.

Ideally the comment would stay on the same line and only the x(rhs.x), ... part be broken over to the next line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions