1 .. title:: clang-tidy - cppcoreguidelines-avoid-const-or-ref-data-members
3 cppcoreguidelines-avoid-const-or-ref-data-members
4 =================================================
6 This check warns when structs or classes that are copyable or movable, and have
7 const-qualified or reference (lvalue or rvalue) data members. Having such
8 members is rarely useful, and makes the class only copy-constructible but not
15 // Bad, const-qualified member
23 int get() const { return x; }
28 // Bad, lvalue reference member
36 std::unique_ptr<int> x;
37 std::shared_ptr<int> x;
41 // Bad, rvalue reference member
46 This check implements `C.12
47 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-constref>`_
48 from the C++ Core Guidelines.
51 `Data members: Never const <https://quuxplusone.github.io/blog/2022/01/23/dont-const-all-the-things/#data-members-never-const>`_.