File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 3
3
bugprone-crtp-constructor-accessibility
4
4
=======================================
5
5
6
- Finds CRTP used in an error-prone way.
6
+ Finds Curiously Recurring Template Pattern used in an error-prone way.
7
+
8
+ The CRTP is an idiom, in which a class derives from a template class, where
9
+ itself is the template argument. It should be ensured that if a class is
10
+ intended to be a base class in this idiom, it can only be instantiated if
11
+ the derived class is it's template argument.
12
+
13
+ Example:
14
+
15
+ .. code-block :: c++
16
+
17
+ template <typename T> class CRTP {
18
+ private:
19
+ CRTP() = default;
20
+ friend T;
21
+ };
22
+
23
+ class Derived : CRTP<Derived> {};
24
+
25
+ Below can be seen some common mistakes that will allow the breaking of the idiom.
7
26
8
27
If the constructor of a class intended to be used in a CRTP is public, then
9
28
it allows users to construct that class on its own.
You can’t perform that action at this time.
0 commit comments