From: Emilio Cobos Alvarez Date: Tue, 2 May 2017 08:32:15 +0000 (+0000) Subject: [libclang] Revert rL301328 and add tests for the regressions introduced. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb56e4e44e49d841dbda9b4734d887ca901f2980;p=clang [libclang] Revert rL301328 and add tests for the regressions introduced. Differential Revision: https://reviews.llvm.org/D32566 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301902 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/print-type.cpp b/test/Index/print-type.cpp index ff150f7dd6..6ecef1abc5 100644 --- a/test/Index/print-type.cpp +++ b/test/Index/print-type.cpp @@ -71,10 +71,9 @@ struct Specialization; Specialization& > templRefParam; auto autoTemplRefParam = templRefParam; -template -struct DefaultedTypeExample {}; - -typedef DefaultedTypeExample DefaultedTypeAlias; +template struct A {}; +template using C = T; +using baz = C>; // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] @@ -120,7 +119,7 @@ typedef DefaultedTypeExample DefaultedTypeAlias; // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0] // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1] // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0] -// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] [typekind=Int]] [canonicaltype=outer::Qux, int>] [canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] [typekind=Int]] [isPOD=1] +// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] [typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] [canonicaltype=outer::Qux, int>] [canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] [typekind=Int]] [isPOD=1] // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0] // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0] // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] [canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] [resulttype=T] [resulttypekind=Unexposed] [isPOD=0] @@ -183,3 +182,4 @@ typedef DefaultedTypeExample DefaultedTypeAlias; // CHECK: UnexposedExpr=templRefParam:71:40 [type=const Specialization &>] [typekind=Unexposed] const [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=const Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1] // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization &>] [typekind=Unexposed] [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1] // CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) [type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] [canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] [canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] [isPOD=0] +// CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] [templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] [typekind=Void]] [isPOD=0] diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index fce7ef2c0d..16e993e2ac 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -147,6 +147,9 @@ static inline CXTranslationUnit GetTU(CXType CT) { static Optional> GetTemplateArguments(QualType Type) { assert(!Type.isNull()); + if (const auto *Specialization = Type->getAs()) + return Specialization->template_arguments(); + if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) { const auto *TemplateDecl = dyn_cast(RecordDecl); @@ -154,9 +157,6 @@ GetTemplateArguments(QualType Type) { return TemplateDecl->getTemplateArgs().asArray(); } - if (const auto *Specialization = Type->getAs()) - return Specialization->template_arguments(); - return None; }