[clang-tools-extra] [clang-tidy] Unsafe CRTP check (PR #82403)

via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 23 12:06:39 PST 2024


================
@@ -0,0 +1,62 @@
+.. title:: clang-tidy - bugprone-unsafe-crtp
+
+bugprone-unsafe-crtp
+====================
+
+Finds CRTP used in an error-prone way.
+
+If the constructor of a class intended to be used in a CRTP is public, then
+it allows users to construct that class on its own.
----------------
isuckatcs wrote:

Quoting [cppreference](https://en.cppreference.com/w/cpp/language/crtp):

> The [Curiously Recurring Template Pattern](https://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern) is an idiom in which a class X derives from a class template Y, taking a template parameter Z, where Y is instantiated with Z = X.

What these lines in the documentain say is bad because they break the `Y is instantiated with Z = X` part. It doesn't do what this idiom says it should do, otherwise from the language's point of view it's perfectly legal.

https://github.com/llvm/llvm-project/pull/82403


More information about the cfe-commits mailing list