]> granicus.if.org Git - clang/commitdiff
Fix templated type alias completion when using global completion cache
authorErik Verbruggen <erikjv@me.com>
Tue, 22 Aug 2017 10:25:48 +0000 (10:25 +0000)
committerErik Verbruggen <erikjv@me.com>
Tue, 22 Aug 2017 10:25:48 +0000 (10:25 +0000)
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
}

Patch by Ivan Donchevskii!

Differential Revision: https://reviews.llvm.org/D35355

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311442 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/ASTUnit.cpp
lib/Parse/ParseTemplate.cpp
test/Index/code-completion.cpp

index 07f847ca944b9e4720dcc01ded9933e157e04cc1..a4a1a5f3b007364b5c6a02e6c1388aa6e3631377 100644 (file)
@@ -243,7 +243,8 @@ static unsigned getDeclShowContexts(const NamedDecl *ND,
   
   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)
index fc1722ea6cd0ea0956c0fce6c4fdbe2d8389dde6..de54f572d821c94bbf4672682d8dee0107d015e5 100644 (file)
@@ -198,9 +198,11 @@ Parser::ParseSingleDeclarationAfterTemplate(
 
   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)
+      return nullptr;
+    return usingDeclPtr.get().getSingleDecl();
   }
 
   // Parse the declaration specifiers, stealing any diagnostics from
@@ -1023,8 +1025,8 @@ bool Parser::AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
             ? OO_None
             : TemplateName.OperatorFunctionId.Operator;
 
-    TemplateIdAnnotation *TemplateId = TemplateIdAnnotation::Create(\r
-      SS, TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind, Template, TNK,\r
+    TemplateIdAnnotation *TemplateId = TemplateIdAnnotation::Create(
+      SS, TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind, Template, TNK,
       LAngleLoc, RAngleLoc, TemplateArgs, TemplateIds);
     
     Tok.setAnnotationValue(TemplateId);
index f52bb10a35b09961adced2e74501458ea65c99db..00f158f3d09da784d5436ed45199fd6e9024d22b 100644 (file)
@@ -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)