[PATCH] [libclang] Check for a record declaration before a template specialization.

Emilio Cobos Álvarez via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 21 06:05:04 PDT 2017


On Fri, Apr 21, 2017 at 01:49:24PM +0100, Alex L wrote:
> Hi,
> 
> On 21 April 2017 at 12:55, Emilio Cobos Álvarez via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
> 
> > This allows us to get the default template parameters too.
> >
> > This patch was submitted also as https://reviews.llvm.org/D31732, but I
> > see no
> > reference to it in cfe-commits or llvm-commits, so I guess it got lost?
> >
> 
> You have to add cfe-commits as subscribers to the Phabricator patch,
> otherwise it won't show up in the mailing list. I would recommend you to
> close the old one revision and create a new one on Phabricator, this way
> we'll get the entire patch history on cfe-commits.

I see, newbie mistake, whoops :)

Will do, thank you!

 -- Emilio

> 
> Alex
> 
> 
> >
> > This fixes bug 32539.
> >
> > Signed-off-by: Emilio Cobos Álvarez <emilio at crisal.io>
> > ---
> >  clang/test/Index/print-type.cpp | 8 +++++++-
> >  clang/tools/libclang/CXType.cpp | 6 +++---
> >  2 files changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/clang/test/Index/print-type.cpp
> > b/clang/test/Index/print-type.cpp
> > index 108ba53c80b..ff150f7dd61 100644
> > --- a/clang/test/Index/print-type.cpp
> > +++ b/clang/test/Index/print-type.cpp
> > @@ -71,6 +71,11 @@ struct Specialization<int>;
> >  Specialization<Specialization<bool>& > templRefParam;
> >  auto autoTemplRefParam = templRefParam;
> >
> > +template<typename T, typename U = int>
> > +struct DefaultedTypeExample {};
> > +
> > +typedef DefaultedTypeExample<int> DefaultedTypeAlias;
> > +
> >  // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
> >  // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid]
> > [isPOD=0]
> >  // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid]
> > [isPOD=0]
> > @@ -115,7 +120,7 @@ auto autoTemplRefParam = templRefParam;
> >  // 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<int, char *,
> > Foo<int>, outer::inner::Bar::FooType>] [typekind=Unexposed]
> > [templateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer]
> > [type=Foo<int>] [typekind=Unexposed] [type=outer::inner::Bar::FooType]
> > [typekind=Typedef]] [canonicaltype=outer::Qux<int, char *, outer::Foo<int>,
> > int>] [canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int]
> > [typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo<int>]
> > [typekind=Record] [type=int] [typekind=Int]] [isPOD=1]
> > +// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux<int, char *,
> > Foo<int>, outer::inner::Bar::FooType>] [typekind=Unexposed]
> > [templateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer]
> > [type=outer::Foo<int>] [typekind=Record] [type=int] [typekind=Int]]
> > [canonicaltype=outer::Qux<int, char *, outer::Foo<int>, int>]
> > [canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int]
> > [typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo<int>]
> > [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]
> > @@ -177,3 +182,4 @@ auto autoTemplRefParam = templRefParam;
> >  // CHECK: VarDecl=autoTemplRefParam:72:6 (Definition)
> > [type=Specialization<Specialization<bool> &>] [typekind=Auto]
> > [templateargs/1= [type=Specialization<bool> &] [typekind=LValueReference]]
> > [canonicaltype=Specialization<Specialization<bool> &>]
> > [canonicaltypekind=Record] [canonicaltemplateargs/1=
> > [type=Specialization<bool> &] [typekind=LValueReference]] [isPOD=1]
> >  // CHECK: UnexposedExpr=templRefParam:71:40 [type=const
> > Specialization<Specialization<bool> &>] [typekind=Unexposed] const
> > [templateargs/1= [type=Specialization<bool> &] [typekind=LValueReference]]
> > [canonicaltype=const Specialization<Specialization<bool> &>]
> > [canonicaltypekind=Record] [canonicaltemplateargs/1=
> > [type=Specialization<bool> &] [typekind=LValueReference]] [isPOD=1]
> >  // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization<Specialization<bool>
> > &>] [typekind=Unexposed] [templateargs/1= [type=Specialization<bool> &]
> > [typekind=LValueReference]] [canonicaltype=Specialization<Specialization<bool>
> > &>] [canonicaltypekind=Record] [canonicaltemplateargs/1=
> > [type=Specialization<bool> &] [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<int,
> > int>] [canonicaltypekind=Record] [canonicaltemplateargs/2= [type=int]
> > [typekind=Int] [type=int] [typekind=Int]] [isPOD=0]
> > diff --git a/clang/tools/libclang/CXType.cpp
> > b/clang/tools/libclang/CXType.cpp
> > index 16e993e2ac0..fce7ef2c0d8 100644
> > --- a/clang/tools/libclang/CXType.cpp
> > +++ b/clang/tools/libclang/CXType.cpp
> > @@ -147,9 +147,6 @@ static inline CXTranslationUnit GetTU(CXType CT) {
> >  static Optional<ArrayRef<TemplateArgument>>
> >  GetTemplateArguments(QualType Type) {
> >    assert(!Type.isNull());
> > -  if (const auto *Specialization = Type->getAs<
> > TemplateSpecializationType>())
> > -    return Specialization->template_arguments();
> > -
> >    if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
> >      const auto *TemplateDecl =
> >        dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl);
> > @@ -157,6 +154,9 @@ GetTemplateArguments(QualType Type) {
> >        return TemplateDecl->getTemplateArgs().asArray();
> >    }
> >
> > +  if (const auto *Specialization = Type->getAs<
> > TemplateSpecializationType>())
> > +    return Specialization->template_arguments();
> > +
> >    return None;
> >  }
> >
> > --
> > 2.12.2
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170421/a36428ad/attachment.sig>


More information about the cfe-commits mailing list