From: Ilya Biryukov Date: Mon, 14 May 2018 13:50:36 +0000 (+0000) Subject: [CodeComplete] Provide completion in decls even for incomplete types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfbf163f3a7e7b19a018d2649cf9c658f863d679;p=clang [CodeComplete] Provide completion in decls even for incomplete types Summary: This change fixes lack of completions in the following case ('^'designates completion points) : void f(^); struct Incomplete; Incomplete g(^); Reviewers: bkramer, aaron.ballman, sammccall Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46639 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332244 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 4ed9d491dd..66b48e775b 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -4493,10 +4493,8 @@ void Sema::CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc, return; // A complete type is needed to lookup for constructors. - if (!isCompleteType(Loc, Type)) - return; - - CXXRecordDecl *RD = Type->getAsCXXRecordDecl(); + CXXRecordDecl *RD = + isCompleteType(Loc, Type) ? Type->getAsCXXRecordDecl() : nullptr; if (!RD) { CodeCompleteExpression(S, Type); return; diff --git a/test/CodeCompletion/incomplete-ret-type.cpp b/test/CodeCompletion/incomplete-ret-type.cpp new file mode 100644 index 0000000000..669105e141 --- /dev/null +++ b/test/CodeCompletion/incomplete-ret-type.cpp @@ -0,0 +1,13 @@ +struct IncompleteType; +int int_value; +typedef int int_typedef; + +void f(in); +IncompleteType g(in); +// Completing should produce results even if types are incomplete. +// Note that clang is expected to return an error code since 'in' does not resolve. +// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:5:9 %s -o - | FileCheck %s +// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:6:19 %s -o - | FileCheck %s +// CHECK: COMPLETION: int{{$}} +// CHECK: COMPLETION: int_typedef +// CHECK: COMPLETION: int_value