From f2d0fdfe812c7f96d8193194a5840ff011aa7ec8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 27 Mar 2014 12:57:40 -0400 Subject: Output: Desugar non-dependent typedef members of class templates Since gccxml does not output uninstantiated templates we must desugar typedef types that would refer to declarations whose context is a template. This is consistent with gccxml behavior. --- src/Output.cxx | 22 +++++++++++++++++++--- test/CMakeLists.txt | 1 + .../gccxml.Class-template-member-Typedef-xml.txt | 22 ++++++++++++++++++++++ test/input/Class-template-member-Typedef.cxx | 6 ++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/expect/gccxml.Class-template-member-Typedef-xml.txt create mode 100644 test/input/Class-template-member-Typedef.cxx diff --git a/src/Output.cxx b/src/Output.cxx index ebbe175..3baf5a9 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -449,9 +449,25 @@ unsigned int ASTVisitor::AddDumpNode(DumpType dt, bool complete) { return this->AddDumpNode(DumpType(tst->desugar(), c), complete); } } break; - case clang::Type::Typedef: - return this->AddDumpNode(t->getAs()->getDecl(), - complete); + case clang::Type::Typedef: { + clang::TypedefType const* tdt = t->getAs(); + if(!tdt->isInstantiationDependentType() && tdt->isSugared()) { + if(clang::DeclContext const* tdc = tdt->getDecl()->getDeclContext()) { + if(clang::CXXRecordDecl const* tdx = + clang::dyn_cast(tdc)) { + if(tdx->getDescribedClassTemplate()) { + // This TypedefType refers to a non-dependent + // TypedefDecl member of a class template. Since gccxml + // format does not include uninstantiated templates we + // must use the desugared type so that we do not end up + // referencing a class template as context. + return this->AddDumpNode(tdt->desugar(), complete); + } + } + } + } + return this->AddDumpNode(tdt->getDecl(), complete); + } break; default: break; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b406172..8c50ce2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -99,6 +99,7 @@ castxml_test_gccxml(Class-member-template) castxml_test_gccxml(Class-template) castxml_test_gccxml(Class-template-Method-Argument-default) castxml_test_gccxml(Class-template-bases) +castxml_test_gccxml(Class-template-member-Typedef) castxml_test_gccxml(Class-template-member-template) castxml_test_gccxml(CvQualifiedType) castxml_test_gccxml(Enumeration) diff --git a/test/expect/gccxml.Class-template-member-Typedef-xml.txt b/test/expect/gccxml.Class-template-member-Typedef-xml.txt new file mode 100644 index 0000000..6458460 --- /dev/null +++ b/test/expect/gccxml.Class-template-member-Typedef-xml.txt @@ -0,0 +1,22 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + + + + + + +$ diff --git a/test/input/Class-template-member-Typedef.cxx b/test/input/Class-template-member-Typedef.cxx new file mode 100644 index 0000000..61db52d --- /dev/null +++ b/test/input/Class-template-member-Typedef.cxx @@ -0,0 +1,6 @@ +template class start { + typedef int Int; +public: + int method(Int); +}; +template class start; -- cgit v0.12