llvm-project
llvm-project copied to clipboard
[clang-tidy] bugprone-crtp-constructor-accessibility for deleted constructor
In this basic example of CRTP pattern:
template<typename D>
class base
{
friend D;
base() = default;
base(const base&) = default;
base(base&&) = delete;
};
class derived : public base<derived>
{
};
I get the following warning, which is expected and reasonable:
project_root/test.cpp:9:3: warning: deleted member function should be public [hicpp-use-equals-delete,modernize-use-equals-delete]
9 | base(base&&) = delete;
| ^
while on the other hand, if I were to move the constructor to the public area:
template<typename D>
class base
{
friend D;
base() = default;
base(const base&) = default;
public:
base(base&&) = delete;
};
class derived : public base<derived>
{
};
the following warning is not needed since the constructor has been deleted:
project_root/testcpp:10:3: warning: public contructor allows the CRTP to be constructed as a regular template class; consider making it private [bugprone-crtp-constructor-accessibility]
10 | base(base&&) = delete;
@llvm/issue-subscribers-clang-tidy
Author: Dimitrije Dobrota (DimitrijeDobrota)
In this basic example of CRTP pattern:
template<typename D>
class base
{
friend D;
base() = default;
base(const base&) = default;
base(base&&) = delete;
};
class derived : public base<derived>
{
};
I get the following warning, which is expected and reasonable:
project_root/test.cpp:9:3: warning: deleted member function should be public [hicpp-use-equals-delete,modernize-use-equals-delete]
9 | base(base&&) = delete;
| ^
while on the other hand, if I were to move the constructor to the public area:
template<typename D>
class base
{
friend D;
base() = default;
base(const base&) = default;
public:
base(base&&) = delete;
};
class derived : public base<derived>
{
};
the following warning is not needed since the constructor has been deleted:
project_root/testcpp:10:3: warning: public contructor allows the CRTP to be constructed as a regular template class; consider making it private [bugprone-crtp-constructor-accessibility]
10 | base(base&&) = delete;
Duplicate of https://github.com/llvm/llvm-project/issues/131737, PR in review state