Skip to content

[BUG|clang-tidy] false positive of misc-unconventional-assign-operator & cppcoreguidelines-c-copy-assignment-signature #143237

@yaoxinliu

Description

@yaoxinliu
struct A {
    explicit A(int) {
    }

    A& operator=(int n) {
        // ok, no clang-tidy warning as expected.
        return *this = A(n); 
    }
};

template<typename T>
struct B {
    explicit B(int) {
    }

    B& operator=(int n) {
        // clang-tidy warning: Operator=() should always return '*this'
        // clang-tidy rule: misc-unconventional-assign-operator
        // clang-tidy rule: cppcoreguidelines-c-copy-assignment-signature
        return *this = B(n); 
    }
};

clang-tidy version: 20.1.5.

This false positive will only be triggered for template classes; It doesn't occur for non-template classes.

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