Bug 408380 - detect useless overrides
Summary: detect useless overrides
Status: REPORTED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-06 12:07 UTC by Milian Wolff
Modified: 2019-09-01 13:32 UTC (History)
2 users (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 Milian Wolff 2019-06-06 12:07:34 UTC
SUMMARY
struct foo { virtual void asdf(); }
struct bar : foo { void asdf() override { foo::asdf(); } }

The override is completely useless, and I find such code far too often - could clazy/clang-tidy detect it and remove the useless code?

it may be problematic to detect when

- non-trivial arguments are forwarded (still useless)
- Q_UNUSED or similar
- instead of calling the parent implementation, the parent implementation code is duplicated:

struct foo { virtual void asdf() { printf("hello");  }
struct bar : foo { void asdf() override { printf("hello"); } }

OBSERVED RESULT
not detected

EXPECTED RESULT
useless overrides are marked and offered for automatic removal
Comment 1 Иван Туманов 2019-06-07 11:56:53 UTC
(In reply to Milian Wolff from comment #0)
> SUMMARY
> struct foo { virtual void asdf(); }
> struct bar : foo { void asdf() override { foo::asdf(); } }
> 
> The override is completely useless, and I find such code far too often -
> could clazy/clang-tidy detect it and remove the useless code?
> 
> it may be problematic to detect when
> 
> - non-trivial arguments are forwarded (still useless)
> - Q_UNUSED or similar
> - instead of calling the parent implementation, the parent implementation
> code is duplicated:
> 
> struct foo { virtual void asdf() { printf("hello");  }
> struct bar : foo { void asdf() override { printf("hello"); } }
> 
> OBSERVED RESULT
> not detected
> 
> EXPECTED RESULT
> useless overrides are marked and offered for automatic removal