Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/slicing.rst

raw
1 .. title:: clang-tidy - cppcoreguidelines-slicing
2
3 cppcoreguidelines-slicing
4 =========================
5
6 Flags slicing of member variables or vtable. Slicing happens when copying a
7 derived object into a base object: the members of the derived object (both
8 member variables and virtual member functions) will be discarded. This can be
9 misleading 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
23 This check implements `ES.63
24 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es63-dont-slice>`_
25 and `C.145
26 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c145-access-polymorphic-objects-through-pointers-and-references>`_
27 from the C++ Core Guidelines.