diff options
Diffstat (limited to 'clang-tools-extra/docs')
-rw-r--r-- | clang-tools-extra/docs/ReleaseNotes.rst | 5 | ||||
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-slicing.rst | 23 |
2 files changed, 27 insertions, 1 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e70bad54acd..e2e9bdbb1b7 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -59,7 +59,10 @@ The improvements are... Improvements to clang-tidy -------------------------- -The improvements are... +- New `cppcoreguidelines-slicing + <http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-slicing.html>`_ check + + Flags slicing of member variables or vtable. Improvements to include-fixer ----------------------------- diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-slicing.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-slicing.rst new file mode 100644 index 00000000000..0b1bb6beed4 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-slicing.rst @@ -0,0 +1,23 @@ +.. title:: clang-tidy - cppcoreguidelines-slicing + +cppcoreguidelines-slicing +========================= + +Flags slicing of member variables or vtable. Slicing happens when copying a +derived object into a base object: the members of the derived object (both +member variables and virtual member functions) will be discarded. +This can be misleading especially for member function slicing, for example: + +.. code:: c++ + + struct B { int a; virtual int f(); }; + struct D : B { int b; int f() override; }; + void use(B b) { // Missing reference, intended ? + b.f(); // Calls B::f. + } + D d; + use(d); // Slice. + +See the relevant CppCoreGuidelines sections for details: +https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es63-dont-slice +https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c145-access-polymorphic-objects-through-pointers-and-references |