-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destructors marked override #208
Comments
Yeah, we are basically seeing the same thing that @jaredgrubb saw with respect to Clang Tidy reporting that destructors should be marked override, which is why we have it there. If you look at the code in Clang Tidy, this is not a bug: This is intentional as in, the developers disagree with @gdr-at-ms. I personally don't see the harm in it (not entirely sure why @gdr-at-ms closed the ticket so abruptly without a better explanation) but if we were to change this, we would have to remove this check entirely, which would be more harm, than marking destructors as override, so for now I would like to keep this as is so that the check can verify the rest of the code properly. Thoughts? |
My thoughts on the issue would be:
With the point stated above, it is the business of the derived class to make sure that its acquired resources are properly released... There is no point in stating override since it can only ever have one signature with no potential for hiding the base destructor... |
Agree 100%. The same applies to all functions that have a base class marked as virtual. All With that in mind, I don't see the "harm" in it. Its really not needed because any derived base class has to have it's base class destructor marked as virtual so 'override' is implied, and I would even go as far as to say the compiler should complain if virtual is missing in the base class (or prevent derivations of a non-virtual base class). My reason saying it should be left like this is that Clang Tidy clearly disagrees. If I fix this and remove the almost "redundant" use of override, I have to disable this check for everything... not just destructors, and I think this check has a lot of value. Since there is no harm in marking destructors with If Clang Tidy developers and @gdr-at-ms can come to an agreement, we can certainly update the code then (by either removing them, or adding them depending on what they agree on). In general, I think that this should have received more discussion, including someone reaching out to the Clang Tidy developers to see what they think / find out why they are enforcing |
Seeing that this issue was opened to keep this repo in conformance with the guidelines, but under analysis it causes more harm than good it can be closed 😄 |
@rianquinn To remove any ambiguity, I am a developer myself, write code on daily basis, and use The note I wrote earlier is the summary of the consensus of the Core Guidelines Editors.
|
@gdr-at-ms I agree. For us at the moment, we are forced to leave this in place as Clang Tidy is enforcing it (as seen in the link above). I either have to completely disable the check, or we have to add I agree with you as it's not needed but since Clang Tidy doesn't we are forced to ignore the Core Guidelines in this case. Since this is an issue for people using both the Core Guidelines and Clang Tidy, consensus should be reached as we are currently left having to disobey someone 😄 and Clang Tidy is really the best linter for Linux users. Has anyone attempted to reach out to the Clang developers? Or is the problem just being ignored? I tried looking for a bug ticket with no success. |
Clang Tidy has a a check called (modernize-use-override) that explicitly verifies that `override` be placed on destructors of derived classes whose base class is `virtual` as seen [here](https://github.com/Microsoft/clang-tools-extra/blob/master/test/clang-tidy/modernize-use-override.cpp#L48). This issue was brought up by @jaredgrubb in the following [ticket](isocpp#721 (comment)) and was also seen [here](Bareflank/hypervisor#208) as well. @gdr-at-ms closed the ticket stating that the C++ Core Guideline Editors have decided that `override` should not be placed on destructors, but the documentation makes no mention of this decision. The following PR addresses this issue. With the documentation updated, an issue ticket can be generated for Clang Tidy to have the destructor check modified to reflect the C++ Core Guidance.
@rianquinn: Thanks for making that pull-request. I think it's nice to have advice on this, whatever the consensus is. I have opened a bug on clang-tidy with references back to this discussion: |
@jaredgrubb No problem. Hopefully a decision is made as this is a real inconvenience. In general, it would be nice to see better collaboration between the guideline editors and the linter tool authors in the future. |
Clang-tidy dev here: we believe that the additional checking we get by having override on the destructor is worth writing it. To me, "override" means that I express the assumption that the derived class' method is called if called through a pointer-to-base. That concept seems to be the same for destructors and normal methods. If that expectation is wrong, getting an error is helpful; both if the underlying base class changes, or if the developer just makes an error and assumes it is virtual. |
@r4nt thanks a ton for responding. Others have said the same thing. I guess for our project, we are looking for consistency (either way doesn't really matter to us as I can see the argument both ways). If you in fact leave the check as is, and @gdr-at-ms is right stating that the Core Guidelines will in fact state the opposite, what is the plan for the core guideline checks in Clang Tidy as they would be mutually exclusive? |
@rianquinn - we generally diverge from the core guidelines where we disagree with them (there are a couple of places, but I think this is the first direct contradiction). I think we would be open to contributions of a core-guidelines module check (we have an extra core guidelines module in clang-tidy) that implements the core-guidelines-compatible version. |
Right now we are using Clang Tidy 3.8 which has a limited number of core guideline checks, with plans to more to Clang Tidy 3.9 in the very near future (we already have libc++ 3.9 support, and I am working on Clang/LLVM 3.8/3.9 support right now). Our verify script can be found here, which is run on each Travis CI build. We basically enable: "cppcoreguidelines-*" which should enable all of the core guidelines that are supported in 3.8, with @r4nt besides "cppcoreguidelines-*" are you suggesting there are a specific set of these tests that are compatible with the others? I guess I am a little confused. I'm a huge fan of the Core Guidelines but to be honest, I'm more a fan of consistency. Arguing over |
@rianquinn If I read @r4nt 's message correctly, it sounds like there is a fundamentally mistaken reinterpretation of |
@gdr-at-ms - I'm not sure where the "reinterpretation" is happening - are you:
There are examples where people have made mistakes that can be prevented by putting override on destructors. I do not understand the reason to not want to catch those mistakes yet. |
From @r4nt's point of view, I can see the value for instance where people inherit from the Guess this check is useful for the ones that are not foresightful of subtle details at the point in time when making use of inheritance... |
@gdr-at-ms is wrong wrt. "You never override a destructor -- virtual destructors are "chained"." The "chained" aspect is completely orthogonal to the overriding. According to [class.virtual]p6: Thus, the use of the 'override' keyword on destructors is in line with the intention of the standard. |
With regard to this issue "
C.128: Should destructors be marked "override"?
"And the comment from @gdr-at-ms
hypervisor's repo should be updated... One such instance can be found here
The text was updated successfully, but these errors were encountered: