Skip to content

readability-redundant-member-init when member variable initialized with macro #152024

@nick-potenski

Description

@nick-potenski

Our code base has a recurring pattern like the following:

#if defined(MY_DEBUG)
#define NAME "debug"
#else
#define NAME
#endif

class Foo {
   public:
    Foo();
    Foo(const char* const aName);
};

class Bar {
   private:
    Foo mFoo{NAME};
};

Which produces the following warning:

<source>:16:13: warning: initializer for member 'mFoo' is redundant [readability-redundant-member-init]
   16 |     Foo mFoo{NAME};
      |             ^~~~~~
1 warning generated.

It is a little more complicated in practice; we use the extra information in debug or profiling builds, but I wanted simplify for the bug report.

Anyway, I noticed that checkers like modernize-use-equals-default recently got support to ignore special member functions with macros used in their bodies. It would be nice if readability-redundant-member-init could do the same thing.

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