From 244b4a70d03762befdd16443feb445540a9e996f Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Wed, 18 Feb 2015 01:32:13 -0700 Subject: [PATCH 1/3] cpptypes: Adjust the aggregate type of a template specialization type to a templated class declaration, if needed. --- dmd2/cpp/cpptypes.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dmd2/cpp/cpptypes.cpp b/dmd2/cpp/cpptypes.cpp index d4cedbd8658..8cde87dbdea 100644 --- a/dmd2/cpp/cpptypes.cpp +++ b/dmd2/cpp/cpptypes.cpp @@ -831,7 +831,9 @@ Type* TypeMapper::FromType::fromTypeTemplateSpecialization(const clang::Template if (T->isSugared()) { - // NOTE: To reduce DMD -> Clang translations to a minimum we don't instantiate ourselves whenever possible, i.e when the template instance is already declared or defined in the PCH. If it's only declared, there's a chance the specialization wasn't emitted in the C++ libraries, so we tell Sema to complete its instantiation. + // NOTE: To reduce DMD -> Clang translations to a minimum we don't instantiate ourselves whenever possible, i.e when + // the template instance is already declared or defined in the PCH. If it's only declared, there's a chance the specialization + // wasn't emitted in the C++ libraries, so we tell Sema to complete its instantiation. auto RT = T->getAs(); @@ -853,7 +855,26 @@ Type* TypeMapper::FromType::fromTypeTemplateSpecialization(const clang::Template } if (!T->isTypeAlias()) + { + if (!RT) + { + clang::TemplateName templateName = T->getTemplateName(); + clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl(); + assert(templateDecl && "could not retrieve template declaration from name"); + + clang::ClassTemplateDecl* classTemplateDecl = dyn_cast(templateDecl); + assert(classTemplateDecl && "could not cast to class template declaration"); + + const clang::CXXRecordDecl* templatedDecl = dyn_cast(classTemplateDecl->getTemplatedDecl()); + assert(templatedDecl && "could not retrieve templated declaration from class templated declaration"); + + return adjustAggregateType(tqual, templatedDecl); + } + return adjustAggregateType(tqual, RT->getDecl()); + } + + return adjustAggregateType(tqual, RT->getDecl()); } return adjustAggregateType(tqual); From 9a17b93ca09d69463b80eb65c7bc6785f626ad5a Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Thu, 19 Feb 2015 12:03:05 -0700 Subject: [PATCH 2/3] cpptypes: Fix that last commit since it was really just an issue with InjectedClassNameTypes --- dmd2/cpp/cpptypes.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/dmd2/cpp/cpptypes.cpp b/dmd2/cpp/cpptypes.cpp index 8cde87dbdea..c324d7e5bc9 100644 --- a/dmd2/cpp/cpptypes.cpp +++ b/dmd2/cpp/cpptypes.cpp @@ -858,17 +858,8 @@ Type* TypeMapper::FromType::fromTypeTemplateSpecialization(const clang::Template { if (!RT) { - clang::TemplateName templateName = T->getTemplateName(); - clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl(); - assert(templateDecl && "could not retrieve template declaration from name"); - - clang::ClassTemplateDecl* classTemplateDecl = dyn_cast(templateDecl); - assert(classTemplateDecl && "could not cast to class template declaration"); - - const clang::CXXRecordDecl* templatedDecl = dyn_cast(classTemplateDecl->getTemplatedDecl()); - assert(templatedDecl && "could not retrieve templated declaration from class templated declaration"); - - return adjustAggregateType(tqual, templatedDecl); + auto ICNT = T->castAs(); + return adjustAggregateType(tqual, ICNT->getDecl()); } return adjustAggregateType(tqual, RT->getDecl()); From 1b10a802dfc842ea78847de3b9c6ecd2a8c3cc82 Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Thu, 19 Feb 2015 15:53:53 -0700 Subject: [PATCH 3/3] cpptypes: remove extraneous return value from first commit --- dmd2/cpp/cpptypes.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/dmd2/cpp/cpptypes.cpp b/dmd2/cpp/cpptypes.cpp index c324d7e5bc9..11f53355c34 100644 --- a/dmd2/cpp/cpptypes.cpp +++ b/dmd2/cpp/cpptypes.cpp @@ -864,8 +864,6 @@ Type* TypeMapper::FromType::fromTypeTemplateSpecialization(const clang::Template return adjustAggregateType(tqual, RT->getDecl()); } - - return adjustAggregateType(tqual, RT->getDecl()); } return adjustAggregateType(tqual);