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

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 3 13:57:56 PDT 2016


ahatanak updated this revision to Diff 76883.
ahatanak added a comment.

Rebase. Pass the destructor's DeclarationNameInfo to the call to RebuildMemberExpr rather than getting it inside 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,23 @@
 
 // The constructor definition should not have errors
 Invalid::~Invalid() {}
+
+namespace PR30361 {
+template <typename T>
+struct C1 {
+  ~C1() {}
+  operator C1<T>* () { return nullptr; }
+  void foo1();
+};
+
+template<typename T>
+void C1<T>::foo1() {
+  C1::operator C1<T>*();
+  C1::~C1();
+}
+
+void foo1() {
+  C1<int> x;
+  x.foo1();
+}
+}
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -8723,11 +8723,16 @@
   // nested-name-qualifier (and therefore could do the lookup).
   NamedDecl *FirstQualifierInScope = nullptr;
 
+  DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
+
+  if (isa<CXXDestructorDecl>(FoundDecl))
+    MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
+
   return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
                                         E->isArrow(),
                                         QualifierLoc,
                                         TemplateKWLoc,
-                                        E->getMemberNameInfo(),
+                                        MemberNameInfo,
                                         Member,
                                         FoundDecl,
                                         (E->hasExplicitTemplateArgs()
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4842,7 +4842,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.76883.patch
Type: text/x-patch
Size: 2357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161103/598d6c10/attachment-0001.bin>


More information about the cfe-commits mailing list