From fdd9dfb4437a55812de0aed9cc8e0e01b42d9030 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 13 Mar 2015 07:39:30 +0000 Subject: [PATCH] [libclang] Fix crash when code-completing inside constructor initializer for a builtin type. rdar://20149746 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232145 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaCodeComplete.cpp | 8 +++++++- test/Index/complete-constructor-params.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 80238e5edb..eeeb8511b2 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -4035,12 +4035,18 @@ void Sema::CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc, if (RequireCompleteType(Loc, Type, 0)) return; + CXXRecordDecl *RD = Type->getAsCXXRecordDecl(); + if (!RD) { + CodeCompleteExpression(S, Type); + return; + } + // FIXME: Provide support for member initializers. // FIXME: Provide support for variadic template constructors. OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Normal); - for (auto C : LookupConstructors(Type->getAsCXXRecordDecl())) { + for (auto C : LookupConstructors(RD)) { if (auto FD = dyn_cast(C)) { AddOverloadCandidate(FD, DeclAccessPair::make(FD, C->getAccess()), Args, CandidateSet, diff --git a/test/Index/complete-constructor-params.cpp b/test/Index/complete-constructor-params.cpp index e5c01df87b..6685626a58 100644 --- a/test/Index/complete-constructor-params.cpp +++ b/test/Index/complete-constructor-params.cpp @@ -14,6 +14,8 @@ int main() { S(42, 42, 42,); S z(42, 42, 42,); + + int(42); } // RUN: c-index-test -code-completion-at=%s:11:10 %s | FileCheck -check-prefix=CHECK-CC1 %s @@ -124,3 +126,15 @@ int main() { // CHECK-CC9-NEXT: Class name // CHECK-CC9-NEXT: Nested name specifier // CHECK-CC9-NEXT: Objective-C interface + +// RUN: c-index-test -code-completion-at=%s:18:7 %s | FileCheck -check-prefix=CHECK-CC10 %s +// CHECK-CC10: FunctionDecl:{ResultType int}{TypedText main}{LeftParen (}{RightParen )} (12) +// CHECK-CC10: Completion contexts: +// CHECK-CC10-NEXT: Any type +// CHECK-CC10-NEXT: Any value +// CHECK-CC10-NEXT: Enum tag +// CHECK-CC10-NEXT: Union tag +// CHECK-CC10-NEXT: Struct tag +// CHECK-CC10-NEXT: Class name +// CHECK-CC10-NEXT: Nested name specifier +// CHECK-CC10-NEXT: Objective-C interface -- 2.40.0