r232145 - [libclang] Fix crash when code-completing inside constructor initializer for a builtin type.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Mar 13 00:39:33 PDT 2015
Author: akirtzidis
Date: Fri Mar 13 02:39:30 2015
New Revision: 232145
URL: http://llvm.org/viewvc/llvm-project?rev=232145&view=rev
Log:
[libclang] Fix crash when code-completing inside constructor initializer for a builtin type.
rdar://20149746
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-constructor-params.cpp
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=232145&r1=232144&r2=232145&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Mar 13 02:39:30 2015
@@ -4035,12 +4035,18 @@ void Sema::CodeCompleteConstructor(Scope
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<FunctionDecl>(C)) {
AddOverloadCandidate(FD, DeclAccessPair::make(FD, C->getAccess()),
Args, CandidateSet,
Modified: cfe/trunk/test/Index/complete-constructor-params.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-constructor-params.cpp?rev=232145&r1=232144&r2=232145&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-constructor-params.cpp (original)
+++ cfe/trunk/test/Index/complete-constructor-params.cpp Fri Mar 13 02:39:30 2015
@@ -14,6 +14,8 @@ int main() {
S<int>(42, 42, 42,);
S<int> 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
More information about the cfe-commits
mailing list