The ABI imposes the practical requirement that the destructors can be called, but the standard does not require access checks here. This is a stab at eliding those access checks to avoid rejecting valid code, as discussed in http://llvm-reviews.chandlerc.com/D2401?id=6089#inline-12829
Details
Diff Detail
Event Timeline
Rather than threading a CheckDtorAccess bool through everywhere, I think you can inline a small portion of the body of FinalizeVarWithDestructor into CheckFunctionDefinition and skip the access check. Most of it is probably dead. That's what I did initially in http://llvm-reviews.chandlerc.com/D929.
Rather than threading a CheckDtorAccess bool through everywhere, I think you can inline a small portion of the body of FinalizeVarWithDestructor into CheckFunctionDefinition and skip the access check. Most of it is probably dead. That's what I did initially in http://llvm-reviews.chandlerc.com/D929.
That just removes one level of threading though. We still need to thread it through MarkFunctionReferenced to suppress access checks for base class dtors etc. when defining an implicit destructor, and that's where the ugliness comes from :/
The problem is that MarkFunctionReferenced does access checks as it marks functions as referenced. This makes perfect sense, except here when we want to be able to call the dtor but bypass the access check.
Richard: it would be interesting to hear your thoughts on this. Is the added plumbing of this boolean variable through the various functions an acceptable approach? Would it be ok to avoid that with some mechanism to "trap" access check errors (maybe a flag on Sema)? Or is it not worth the hassle to change this?
I don't think we should elide these checks. This would lead us to behave
differently than MSVC inside of SFINAE contexts.
Sent from my phone.
I think you should only be removing the direct access check of the parameter type, and not handling the base and member access checks -- they're effectively part of generating the destructor definition for the parameter's type, and aren't affected by which TU the check is performed in.
I don't think we should elide these checks. This would lead us to behave
differently than MSVC inside of SFINAE contexts.
If I understand correctly, these checks only occur as part of handling a function definition, which is not a SFINAE context, so I think this is not an issue.
Thanks Richard! New patch attached/uploaded that only elides the direct access check. Does this look OK?