brintos

brintos / llvm-project-archived public Read only

0
0
Text · 897 B · dd81365 Raw
28 lines · plain
1.. title:: clang-tidy - cppcoreguidelines-slicing2 3cppcoreguidelines-slicing4=========================5 6Flags slicing of member variables or vtable. Slicing happens when copying a7derived object into a base object: the members of the derived object (both8member variables and virtual member functions) will be discarded. This can be9misleading 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.6324<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es63-dont-slice>`_25and `C.14526<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c145-access-polymorphic-objects-through-pointers-and-references>`_27from the C++ Core Guidelines.28