Skip to content

Remove duplicated non-virtual base-class method#3327

Merged
andypugh merged 1 commit intoLinuxCNC:masterfrom
BsAtHome:fix_dup-inherit-method
Feb 6, 2025
Merged

Remove duplicated non-virtual base-class method#3327
andypugh merged 1 commit intoLinuxCNC:masterfrom
BsAtHome:fix_dup-inherit-method

Conversation

@BsAtHome
Copy link
Copy Markdown
Contributor

@BsAtHome BsAtHome commented Feb 6, 2025

A non-virtual method cannot be "properly" overloaded. It is also a pointless construct because the base-class method claims it should never be called. Therefore, it should not exists at all, resulting in it never being called (and the compiler will error if you try).

This particular method cannot be made virtual because of the vtable, which cannot be located in shared memory (pointers are not valid across shmem maps). Anyway, there is no point in having it at all in the base-class. Derived classes must declare and define it where necessary.

Cppcheck found this issue [duplInheritedMember] and this PR is the first part of fixing the this problem class. This PR roughly halves the reported instances of the warning.

@andypugh
Copy link
Copy Markdown
Collaborator

andypugh commented Feb 6, 2025

It looks like it exists to trap improper usage? All it does is say "you shouldn't have called me".

@BsAtHome
Copy link
Copy Markdown
Contributor Author

BsAtHome commented Feb 6, 2025

And that is exactly why it is pointless.
If it was a virtual function, then it would have made some sense (making it abstract would have been better). However, it is a normal method and it cannot be virtual due to its place in shared memory.

Therefore, if you don't want this base-class method to get called, ever, then you simply don't include it in the base (!) class.

@andypugh andypugh merged commit d7588c4 into LinuxCNC:master Feb 6, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants