diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-04-14 20:33:34 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-04-14 20:33:34 +0000 |
commit | 3e64d56185f0bf7dbd536c1b3ecbc853c22a9184 (patch) | |
tree | 5073ecdb1543053b3a53481f97da83b00e6dff19 /lib/Sema/SemaCodeComplete.cpp | |
parent | 414d8967e1d760ea1e19a4aca96b13777a8cf8c5 (diff) |
When determining the "usage" type of a declaration for the purposes of code
completion, look through block pointer and function pointer types to the
result type of the block/function. Fixes <rdar://problem/9282583>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129535 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 75253b5b30..12ce270c74 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -667,8 +667,39 @@ QualType clang::getDeclUsageType(ASTContext &C, NamedDecl *ND) { T = Value->getType(); else return QualType(); - - return T.getNonReferenceType(); + + // Dig through references, function pointers, and block pointers to + // get down to the likely type of an expression when the entity is + // used. + do { + if (const ReferenceType *Ref = T->getAs<ReferenceType>()) { + T = Ref->getPointeeType(); + continue; + } + + if (const PointerType *Pointer = T->getAs<PointerType>()) { + if (Pointer->getPointeeType()->isFunctionType()) { + T = Pointer->getPointeeType(); + continue; + } + + break; + } + + if (const BlockPointerType *Block = T->getAs<BlockPointerType>()) { + T = Block->getPointeeType(); + continue; + } + + if (const FunctionType *Function = T->getAs<FunctionType>()) { + T = Function->getResultType(); + continue; + } + + break; + } while (true); + + return T; } void ResultBuilder::AdjustResultPriorityForDecl(Result &R) { |