[cfe-commits] r82307 - in /cfe/trunk: lib/Sema/CodeCompleteConsumer.cpp test/CodeCompletion/nested-name-specifier.cpp
Douglas Gregor
dgregor at apple.com
Fri Sep 18 16:55:56 PDT 2009
Author: dgregor
Date: Fri Sep 18 18:55:56 2009
New Revision: 82307
URL: http://llvm.org/viewvc/llvm-project?rev=82307&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/test/CodeCompletion/nested-name-specifier.cpp
Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=82307&r1=82306&r2=82307&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Fri Sep 18 18:55:56 2009
@@ -116,9 +116,22 @@
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 @@
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());
Modified: cfe/trunk/test/CodeCompletion/nested-name-specifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/nested-name-specifier.cpp?rev=82307&r1=82306&r2=82307&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/nested-name-specifier.cpp (original)
+++ cfe/trunk/test/CodeCompletion/nested-name-specifier.cpp Fri Sep 18 18:55:56 2009
@@ -15,5 +15,4 @@
// CHECK-CC1: A : 0
// CHECK-CC1: B : 0
// CHECK-CC1: M : 0
-// CHECK-CC1: template : 0
N::
\ No newline at end of file
More information about the cfe-commits
mailing list