1.. title:: clang-tidy - cppcoreguidelines-slicing 2 3cppcoreguidelines-slicing 4========================= 5 6Flags slicing of member variables or vtable. Slicing happens when copying a 7derived object into a base object: the members of the derived object (both 8member variables and virtual member functions) will be discarded. This can be 9misleading especially for member function slicing, for example: 10 11.. code-block:: c++ 12 13 struct B { int a; virtual int f(); }; 14 struct D : B { int b; int f() override; }; 15 16 void use(B b) { // Missing reference, intended? 17 b.f(); // Calls B::f. 18 } 19 20 D d; 21 use(d); // Slice. 22 23This check implements `ES.63 24<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es63-dont-slice>`_ 25and `C.145 26<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c145-access-polymorphic-objects-through-pointers-and-references>`_ 27from the C++ Core Guidelines. 28