Skip to content

false positive cppcoreguidelines-prefer-member-initializer warning, applying tweak produces broken code #157734

@geza-herman

Description

@geza-herman

See this example:

struct Base {
    int a = 0;
};

template <typename T>
struct Der: Base {
    Der() {
        a = 1;
    }
};

clang-tidy produces cppcoreguidelines-prefer-member-initializer warning for a = 1 in Der. Applying the suggested tweak (puts a(1) into Der's member initializer list) creates broken code.

If Der is not a template, this problem doesn't happen.

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