Suggested patch for pr22394
Richard Smith
richard at metafoo.co.uk
Fri Jan 30 15:47:52 PST 2015
On Fri, Jan 30, 2015 at 2:48 PM, jahanian <fjahanian at apple.com> wrote:
> This patch attempts to fix a crash during instantiation of a direct
> destructor call; as in foo::~foo().
> Please review.
Hmm, we're looking up the wrong name. D->getDeclName() will be the name of
the primary template's destructor; we should transform that name prior to
the call to lookup so that we look up the destructor of the specialization.
While playing with this, I found we also assert for:
template<typename T> struct X { operator X(); void f() { &operator X; } };
... which may or may not be related.
We also reject-valid on this reduced case:
template<typename T> struct X { void f() { X::~X(); } };
... which is a different bug (lookup fails because we've not actually
declared ~X() yet, and we choose to not do so because we're in a dependent
context), but we should first figure out how we'll tackle it because that
informs the change we make here. In particular:
+ if (isa<CXXDestructorDecl>(D)) {
+ if (CXXRecordDecl *Spec = dyn_cast<CXXRecordDecl>(ParentDC))
+ if (!Spec->isDependentContext())
+ Result = LookupDestructor(Spec);
LookupDestructor may implicitly declare the destructor, which should never
be necessary if the template had a declared destructor; calling lookup /
findInstantiationOf with the appropriate DeclarationName would be better in
that case. If on the other hand the template might have an
implicitly-declared destructor, LookupDestructor is appropriate here (but
might be problematic for other reasons, if the class is not yet complete).
+ } else {
+ DeclContext::lookup_result Found =
ParentDC->lookup(D->getDeclName());
+ Result = findInstantiationOf(Context, D, Found.begin(),
Found.end());
Weird indentation.
+ DeclarationNameInfo NameInfo = !isa<CXXDestructorDecl>(FoundDecl)
+ ? E->getMemberNameInfo()
+ :
DeclarationNameInfo(FoundDecl->getDeclName(),
+
FoundDecl->getLocation());
This is wrong: you want the location of the destructor-name here, not the
location of the declaration of the destructor. Instead of this change, you
should call TransformDeclarationNameInfo. (It looks like we get conversion
function names wrong here too.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150130/4a98fd5e/attachment.html>
More information about the cfe-commits
mailing list