[PATCH] D24969: [Sema] Use the instantiated name of destructors in FindInstantiatedDecl and RebuildMemberExpr

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 09:15:39 PDT 2016


ahatanak created this revision.
ahatanak added reviewers: doug.gregor, rsmith.
ahatanak added a subscriber: cfe-commits.

This fixes PR30361.

clang was failing to compile the test case because it was passing "~C1<T>" instead of "~C1" to FindInstantiatedDecl and RebuildMemberExpr.

https://reviews.llvm.org/D24969

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/TreeTransform.h
  test/SemaCXX/destructor.cpp

Index: test/SemaCXX/destructor.cpp
===================================================================
--- test/SemaCXX/destructor.cpp
+++ test/SemaCXX/destructor.cpp
@@ -431,3 +431,21 @@
 
 // The constructor definition should not have errors
 Invalid::~Invalid() {}
+
+namespace PR30361 {
+template <typename T>
+struct C1 {
+  ~C1() {}
+  void foo1();
+};
+
+template<typename T>
+void C1<T>::foo1() {
+  C1::~C1();
+}
+
+void foo1() {
+  C1<int> x;
+  x.foo1();
+}
+}
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2122,6 +2122,11 @@
                                NamedDecl *FirstQualifierInScope) {
     ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
                                                                       isArrow);
+    DeclarationNameInfo DNI = MemberNameInfo;
+
+    if (isa<CXXDestructorDecl>(FoundDecl))
+      DNI = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
+
     if (!Member->getDeclName()) {
       // We have a reference to an unnamed field.  This is always the
       // base of an anonymous struct/union member access, i.e. the
@@ -2139,7 +2144,7 @@
       Base = BaseResult.get();
       ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
       MemberExpr *ME = new (getSema().Context)
-          MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
+          MemberExpr(Base, isArrow, OpLoc, Member, DNI,
                      cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
       return ME;
     }
@@ -2152,7 +2157,7 @@
 
     // FIXME: this involves duplicating earlier analysis in a lot of
     // cases; we should avoid this when possible.
-    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
+    LookupResult R(getSema(), DNI, Sema::LookupMemberName);
     R.addDecl(FoundDecl);
     R.resolveKind();
 
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4845,7 +4845,11 @@
 
     NamedDecl *Result = nullptr;
     if (D->getDeclName()) {
-      DeclContext::lookup_result Found = ParentDC->lookup(D->getDeclName());
+      DeclarationName Name = D->getDeclName();
+      if (auto *DD = dyn_cast<CXXDestructorDecl>(D))
+        Name =
+            SubstDeclarationNameInfo(DD->getNameInfo(), TemplateArgs).getName();
+      DeclContext::lookup_result Found = ParentDC->lookup(Name);
       Result = findInstantiationOf(Context, D, Found.begin(), Found.end());
     } else {
       // Since we don't have a name for the entity we're looking for,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24969.72664.patch
Type: text/x-patch
Size: 2747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160927/b7eaa5af/attachment.bin>


More information about the cfe-commits mailing list