Bug 438027 - copyable-polymorphic should not issue a warning when the base class copy ctor isn't public
Summary: copyable-polymorphic should not issue a warning when the base class copy ctor...
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-03 10:55 UTC by David Faure
Modified: 2021-06-03 21:50 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Faure 2021-06-03 10:55:00 UTC
SUMMARY
copyable-polymorphic gives unfixable warnings when using a protected copy constructor in the base class, and clone() virtual methods in subclasses. Or final subclasses that can't be derived from. Copying is "safe" in such cases, except when slicing *this internally, but we can't do anything about that.

Well, that would be for a different check: detecting actual slicing at the time it happens... but for library authors, I guess this check still makes sense, if it only warns for *public* copy constructors.

STEPS TO REPRODUCE
1. cd training-material/addon/cpp11/misc/sol-modernize; mkdir build-clazy
2. cmake .. -DCMAKE_CXX_COMPILER=clazy
3. export CLAZY_CHECKS='copyable-polymorphic'
4. make

OBSERVED RESULT

/d/kdab/src/training-material/addon/cpp11/misc/sol-modernize/modernize.cpp:22:1: warning: Polymorphic class Person is copyable. Potential slicing. [-Wclazy-copyable-polymorphic]
class Person
^
/d/kdab/src/training-material/addon/cpp11/misc/sol-modernize/modernize.cpp:46:1: warning: Polymorphic class Employee is copyable. Potential slicing. [-Wclazy-copyable-polymorphic]
class Employee : public Person
^
2 warnings generated.

EXPECTED RESULT

No such warning when the base class' copy constructor is protected

SOFTWARE/OS VERSIONS
clazy git master from today
Comment 1 Sergio Martins 2021-06-03 21:50:21 UTC
Git commit 9ec85f78a18c031e49cdc62517175bfee7ee92ea by Sergio Martins.
Committed on 03/06/2021 at 21:45.
Pushed by smartins into branch 'master'.

copyable-polymorphic: Don't warn for some final classes

If the class is final and its base classes don't have public
copy-ctor/assign then it's ok
Related: bug 430672

M  +28   -4    src/checks/level2/copyable-polymorphic.cpp
M  +23   -0    tests/copyable-polymorphic/main.cpp
M  +1    -0    tests/copyable-polymorphic/main.cpp.expected

https://invent.kde.org/sdk/clazy/commit/9ec85f78a18c031e49cdc62517175bfee7ee92ea