Skip to content

[clang-tidy] False positive modernize-use-default-member-init warning in clang-tidy-21 #160394

Description

@hebasto

For the following code:

struct A
{
    A(int i) : f((i & 0x1f) == 1) {}
    bool f;
};

clang-tidy-21 produces a false positive warning:

$ clang-tidy-21 test.cpp -checks=modernize-* --
1 warning generated.
<redacted>/test.cpp:4:10: warning: use default member initializer for 'f' [modernize-use-default-member-init]
    3 |     A(int i) : f((i & 0x1f) == 1) {}
      |                ~~~~~~~~~~~~~~~~~~
    4 |     bool f;
      |          ^
      |           {(i & 0x1f) == 1}

cland-tidy-20 works just fine.

$ clang-tidy-21 --version
Ubuntu LLVM version 21.1.2
  Optimized build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions