From: Benjamin Kramer Date: Thu, 9 Jul 2015 15:31:10 +0000 (+0000) Subject: [CodeCompletion] Don't crash on member inits of templated constructors. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2948658dcabc0724f3d62089d04c88fc4d462dd;p=clang [CodeCompletion] Don't crash on member inits of templated constructors. Also fixes a crash (on invalid) member functions with a colon initializer. PR23948. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241811 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 252e30563e..86265275d0 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -4409,9 +4409,12 @@ void Sema::CodeCompleteOperatorName(Scope *S) { void Sema::CodeCompleteConstructorInitializer( Decl *ConstructorD, ArrayRef Initializers) { - PrintingPolicy Policy = getCompletionPrintingPolicy(*this); - CXXConstructorDecl *Constructor - = static_cast(ConstructorD); + if (!ConstructorD) + return; + + AdjustDeclIfTemplate(ConstructorD); + + CXXConstructorDecl *Constructor = dyn_cast(ConstructorD); if (!Constructor) return; @@ -4435,6 +4438,7 @@ void Sema::CodeCompleteConstructorInitializer( // Add completions for base classes. CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); + PrintingPolicy Policy = getCompletionPrintingPolicy(*this); bool SawLastInitializer = Initializers.empty(); CXXRecordDecl *ClassDecl = Constructor->getParent(); for (const auto &Base : ClassDecl->bases()) { diff --git a/test/Index/complete-ctor-inits.cpp b/test/Index/complete-ctor-inits.cpp index f50621466f..0870cb2f82 100644 --- a/test/Index/complete-ctor-inits.cpp +++ b/test/Index/complete-ctor-inits.cpp @@ -17,6 +17,18 @@ struct Z : public X, public Y { Z::Z() : ::X(0), Virt(), b(), c() { } +struct PR23948 { + template PR23948() + : + {} + + template void invalid() + : + {} + + int a; +}; + // RUN: c-index-test -code-completion-at=%s:18:10 %s | FileCheck -check-prefix=CHECK-CC1 %s // CHECK-CC1: MemberRef:{TypedText a}{LeftParen (}{Placeholder args}{RightParen )} (35) // CHECK-CC1: MemberRef:{TypedText b}{LeftParen (}{Placeholder args}{RightParen )} (35) @@ -38,3 +50,7 @@ Z::Z() : ::X(0), Virt(), b(), c() { } // CHECK-CC3: MemberRef:{TypedText c}{LeftParen (}{Placeholder args}{RightParen )} (7) // CHECK-CC3-NOT: NotImplemented:{TypedText Virt}{LeftParen (}{Placeholder args}{RightParen )} // CHECK-CC3: NotImplemented:{TypedText Y}{LeftParen (}{Placeholder args}{RightParen )} (35) + +// RUN: c-index-test -code-completion-at=%s:22:10 %s | FileCheck -check-prefix=CHECK-CC4 %s +// CHECK-CC4: MemberRef:{TypedText a}{LeftParen (}{Placeholder args}{RightParen )} (7) +// RUN: c-index-test -code-completion-at=%s:26:10 %s