From 03b70d4fa4bd2e091608cbf954d5396c79c9cab2 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Mon, 27 Aug 2018 08:41:06 +0200 Subject: [backported/clang-8][libclang] Return the proper pointee type for 'auto' deduced to pointer -------------------------------------------------------------------------- * https://reviews.llvm.org/D51281 -------------------------------------------------------------------------- Currently the resulting type is always invalid in such case. This is a cherry pick from commit 5d08e4bd09e184ec138fad141ca1fb2bca9e5091 Change-Id: Ic0c9be8c44905d286af38980e4dd65c51f64f0d9 Reviewed-by: Nikolai Kosjar --- test/Index/print-type.cpp | 3 +++ tools/libclang/CXType.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/test/Index/print-type.cpp b/test/Index/print-type.cpp index e152a7ed3d..3c76c97cca 100644 --- a/test/Index/print-type.cpp +++ b/test/Index/print-type.cpp @@ -75,6 +75,8 @@ template struct A {}; template using C = T; using baz = C>; +auto autoTemplPointer = &autoTemplRefParam; + // 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] @@ -182,3 +184,4 @@ using baz = C>; // 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: 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] +// CHECK: VarDecl=autoTemplPointer:78:6 (Definition) [type=Specialization &> *] [typekind=Auto] [canonicaltype=Specialization &> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=Specialization &>] [pointeekind=Record] diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 7c0f307944..c3fdcc504f 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -437,6 +437,7 @@ CXType clang_getPointeeType(CXType CT) { if (!TP) return MakeCXType(QualType(), GetTU(CT)); +try_again: switch (TP->getTypeClass()) { case Type::Pointer: T = cast(TP)->getPointeeType(); @@ -454,6 +455,12 @@ CXType clang_getPointeeType(CXType CT) { case Type::MemberPointer: T = cast(TP)->getPointeeType(); break; + case Type::Auto: + case Type::DeducedTemplateSpecialization: + TP = cast(TP)->getDeducedType().getTypePtrOrNull(); + if (TP) + goto try_again; + break; default: T = QualType(); break; -- cgit v1.2.3