Author: erikjv Date: Fri Sep 8 02:31:13 2017 New Revision: 312780 URL: http://llvm.org/viewvc/llvm-project?rev=312780&view=rev Log: Fix templated type alias completion when using global completion cache
When we have enabled cache for global completions we did not have diagnostics for Bar and could not complete Ba as in provided code example. template <typename T> struct Foo { T member; }; template<typename T> using Bar = Foo<T>; int main() { Ba } (This is the fixed version of r 311442, which was reverted in r311445.) Patch by Ivan Donchevskii! Differential Revision: https://reviews.llvm.org/D35355 Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/lib/Parse/ParseTemplate.cpp cfe/trunk/test/Index/code-completion.cpp Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=312780&r1=312779&r2=312780&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Sep 8 02:31:13 2017 @@ -243,7 +243,8 @@ static unsigned getDeclShowContexts(cons uint64_t Contexts = 0; if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND) || - isa<ClassTemplateDecl>(ND) || isa<TemplateTemplateParmDecl>(ND)) { + isa<ClassTemplateDecl>(ND) || isa<TemplateTemplateParmDecl>(ND) || + isa<TypeAliasTemplateDecl>(ND)) { // Types can appear in these contexts. if (LangOpts.CPlusPlus || !isa<TagDecl>(ND)) Contexts |= (1LL << CodeCompletionContext::CCC_TopLevel) Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=312780&r1=312779&r2=312780&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseTemplate.cpp (original) +++ cfe/trunk/lib/Parse/ParseTemplate.cpp Fri Sep 8 02:31:13 2017 @@ -197,10 +197,11 @@ Parser::ParseSingleDeclarationAfterTempl MaybeParseCXX11Attributes(prefixAttrs); if (Tok.is(tok::kw_using)) { - // FIXME: We should return the DeclGroup to the caller. - ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd, - prefixAttrs); - return nullptr; + auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd, + prefixAttrs); + if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl()) + return nullptr; + return usingDeclPtr.get().getSingleDecl(); } // Parse the declaration specifiers, stealing any diagnostics from Modified: cfe/trunk/test/Index/code-completion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/code-completion.cpp?rev=312780&r1=312779&r2=312780&view=diff ============================================================================== --- cfe/trunk/test/Index/code-completion.cpp (original) +++ cfe/trunk/test/Index/code-completion.cpp Fri Sep 8 02:31:13 2017 @@ -37,6 +37,16 @@ Z::operator int() const { return 0; } +template <typename T> +struct Foo { T member; }; + +template<typename T> using Bar = Foo<T>; + +void test_template_alias() { + // RUN: env CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:47:1 %s | FileCheck -check-prefix=CHECK-TEMPLATE-ALIAS %s + +} + // CHECK-MEMBER: FieldDecl:{ResultType double}{TypedText member} // CHECK-MEMBER: FieldDecl:{ResultType int}{Text X::}{TypedText member} // CHECK-MEMBER: FieldDecl:{ResultType float}{Text Y::}{TypedText member} @@ -88,3 +98,5 @@ Z::operator int() const { // CHECK-EXPR-NEXT: Class name // CHECK-EXPR-NEXT: Nested name specifier // CHECK-EXPR-NEXT: Objective-C interface + +// CHECK-TEMPLATE-ALIAS: AliasTemplateDecl:{TypedText Bar}{LeftAngle <}{Placeholder typename T}{RightAngle >} (50) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits