[clang-tools-extra] [clang-tidy] Unsafe CRTP check (PR #82403)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 20 12:23:54 PST 2024
================
@@ -0,0 +1,232 @@
+// RUN: %check_clang_tidy %s bugprone-unsafe-crtp %t
+
+namespace class_implicit_ctor {
+template <typename T>
+class CRTP {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: the implicit default constructor of the CRTP is publicly accessible [bugprone-unsafe-crtp]
+// CHECK-MESSAGES: :[[@LINE-2]]:7: note: consider making it private
----------------
PiotrZSL wrote:
with private constructor this code wont compile:
```
template <typename T>
class CRTP {
private:
CRTP() = default;
};
class A : CRTP<A> {
public:
A() = default;
};
void test()
{
A a;
}
<source>:9:5: warning: explicitly defaulted default constructor is implicitly deleted [-Wdefaulted-function-deleted]
<source>:7:11: note: default constructor of 'A' is implicitly deleted because base class 'CRTP<A>' has an inaccessible default constructor
<source>:14:7: error: call to implicitly-deleted default constructor of 'A'
```
https://github.com/llvm/llvm-project/pull/82403
More information about the cfe-commits
mailing list