Skip to content

[clang-tidy] Using an aliased name of a class for its copy/move/assignment constructors/operators produces a false positive cppcoreguidelines-special-member-functions warning. #116055

@crud89

Description

@crud89

The following class produces a false positive Wcppcoreguidelines-special-member-functions with LLVM 19.1.3:

template <typename T, unsigned ROWS, unsigned COLS> requires (ROWS >= 2 && COLS >= 2)
class Mat {
public:
	static constexpr size_t mat_rows = ROWS;
	static constexpr size_t mat_cols = COLS;

	using scalar_type = T;
	using mat_type = Mat<scalar_type, mat_rows, mat_cols>;

protected:
	using array_type = std::array<scalar_type, mat_rows* mat_cols>;

private:
	array_type m_elements = { };

public:
	constexpr Mat() noexcept = default;

	constexpr Mat(const mat_type& _other) noexcept {
		std::ranges::copy(_other.m_elements, std::begin(m_elements));
	}

	constexpr Mat(mat_type&& _other) noexcept :
		m_elements{ std::move(_other.m_elements) } {
	}

	virtual ~Mat() noexcept = default;

	constexpr auto& operator=(const mat_type& _other) noexcept {
		std::ranges::copy(_other.m_elements, std::begin(m_elements));
		return *this;
	}

	constexpr auto& operator=(mat_type&& _other) noexcept {
		m_elements = std::move(_other.m_elements);
		return *this;
	}
};

This happens due to the alias using mat_type = Mat<scalar_type, mat_rows, mat_cols>;. If I replace the alias mat_type in the constructors and assignment operators with the full class name, the warning goes away.

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