diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-18 23:55:56 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-18 23:55:56 +0000 |
commit | ff360b64a63ebaf3c42ee75b6cf1aae8972c6280 (patch) | |
tree | c0203afca9a19b5a56f2390ed7bfe7bcc94f00bc | |
parent | 63f07c55d58951574afe9bbb9f7cb3f92eecdd9b (diff) |
In C++ code completion, only suggest the "template" keyword after ".",
"->", or "::" if we will be looking into a dependent context. It's not
wrong to use the "template" keyword, but it's to needed, either.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82307 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/CodeCompleteConsumer.cpp | 22 | ||||
-rw-r--r-- | test/CodeCompletion/nested-name-specifier.cpp | 1 |
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index 8c8d6a1831..2e3d5cd88e 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -116,9 +116,22 @@ CodeCompleteConsumer::CodeCompleteMemberReferenceExpr(Scope *S, NextRank = CollectMemberLookupResults(Record->getDecl(), NextRank, Results); if (getSema().getLangOptions().CPlusPlus) { - if (!Results.empty()) + if (!Results.empty()) { // The "template" keyword can follow "->" or "." in the grammar. - Results.MaybeAddResult(Result("template", NextRank++)); + // However, we only want to suggest the template keyword if something + // is dependent. + bool IsDependent = BaseType->isDependentType(); + if (!IsDependent) { + for (Scope *DepScope = S; DepScope; DepScope = DepScope->getParent()) + if (DeclContext *Ctx = (DeclContext *)DepScope->getEntity()) { + IsDependent = Ctx->isDependentContext(); + break; + } + } + + if (IsDependent) + Results.MaybeAddResult(Result("template", NextRank++)); + } // We could have the start of a nested-name-specifier. Add those // results as well. @@ -177,8 +190,9 @@ CodeCompleteConsumer::CodeCompleteQualifiedId(Scope *S, ResultSet Results(*this); unsigned NextRank = CollectMemberLookupResults(Ctx, 0, Results); - // The "template" keyword can follow "::" in the grammar - if (!Results.empty()) + // The "template" keyword can follow "::" in the grammar, but only + // put it into the grammar if the nested-name-specifier is dependent. + if (!Results.empty() && NNS->isDependent()) Results.MaybeAddResult(Result("template", NextRank)); ProcessCodeCompleteResults(Results.data(), Results.size()); diff --git a/test/CodeCompletion/nested-name-specifier.cpp b/test/CodeCompletion/nested-name-specifier.cpp index f418164b02..4d6a75f8cb 100644 --- a/test/CodeCompletion/nested-name-specifier.cpp +++ b/test/CodeCompletion/nested-name-specifier.cpp @@ -15,5 +15,4 @@ namespace N { // CHECK-CC1: A : 0 // CHECK-CC1: B : 0 // CHECK-CC1: M : 0 -// CHECK-CC1: template : 0 N::
\ No newline at end of file |