@@ -44,11 +44,16 @@ clang::getTemplateParamsRange(TemplateParameterList const * const *Ps,
44
44
// / of a template and, if so, return that template declaration. Otherwise,
45
45
// / returns NULL.
46
46
static NamedDecl *isAcceptableTemplateName (ASTContext &Context,
47
- NamedDecl *Orig) {
47
+ NamedDecl *Orig,
48
+ bool AllowFunctionTemplates) {
48
49
NamedDecl *D = Orig->getUnderlyingDecl ();
49
50
50
- if (isa<TemplateDecl>(D))
51
+ if (isa<TemplateDecl>(D)) {
52
+ if (!AllowFunctionTemplates && isa<FunctionTemplateDecl>(D))
53
+ return 0 ;
54
+
51
55
return Orig;
56
+ }
52
57
53
58
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
54
59
// C++ [temp.local]p1:
@@ -78,13 +83,15 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context,
78
83
return 0 ;
79
84
}
80
85
81
- void Sema::FilterAcceptableTemplateNames (LookupResult &R) {
86
+ void Sema::FilterAcceptableTemplateNames (LookupResult &R,
87
+ bool AllowFunctionTemplates) {
82
88
// The set of class templates we've already seen.
83
89
llvm::SmallPtrSet<ClassTemplateDecl *, 8 > ClassTemplates;
84
90
LookupResult::Filter filter = R.makeFilter ();
85
91
while (filter.hasNext ()) {
86
92
NamedDecl *Orig = filter.next ();
87
- NamedDecl *Repl = isAcceptableTemplateName (Context, Orig);
93
+ NamedDecl *Repl = isAcceptableTemplateName (Context, Orig,
94
+ AllowFunctionTemplates);
88
95
if (!Repl)
89
96
filter.erase ();
90
97
else if (Repl != Orig) {
@@ -114,9 +121,10 @@ void Sema::FilterAcceptableTemplateNames(LookupResult &R) {
114
121
filter.done ();
115
122
}
116
123
117
- bool Sema::hasAnyAcceptableTemplateNames (LookupResult &R) {
124
+ bool Sema::hasAnyAcceptableTemplateNames (LookupResult &R,
125
+ bool AllowFunctionTemplates) {
118
126
for (LookupResult::iterator I = R.begin (), IEnd = R.end (); I != IEnd; ++I)
119
- if (isAcceptableTemplateName (Context, *I))
127
+ if (isAcceptableTemplateName (Context, *I, AllowFunctionTemplates ))
120
128
return true ;
121
129
122
130
return false ;
@@ -268,13 +276,13 @@ void Sema::LookupTemplateName(LookupResult &Found,
268
276
}
269
277
270
278
bool ObjectTypeSearchedInScope = false ;
279
+ bool AllowFunctionTemplatesInLookup = true ;
271
280
if (LookupCtx) {
272
281
// Perform "qualified" name lookup into the declaration context we
273
282
// computed, which is either the type of the base of a member access
274
283
// expression or the declaration context associated with a prior
275
284
// nested-name-specifier.
276
285
LookupQualifiedName (Found, LookupCtx);
277
-
278
286
if (!ObjectType.isNull () && Found.empty ()) {
279
287
// C++ [basic.lookup.classref]p1:
280
288
// In a class member access expression (5.2.5), if the . or -> token is
@@ -287,6 +295,7 @@ void Sema::LookupTemplateName(LookupResult &Found,
287
295
// or function template.
288
296
if (S) LookupName (Found, S);
289
297
ObjectTypeSearchedInScope = true ;
298
+ AllowFunctionTemplatesInLookup = false ;
290
299
}
291
300
} else if (isDependent && (!S || ObjectType.isNull ())) {
292
301
// We cannot look into a dependent object type or nested nme
@@ -296,6 +305,9 @@ void Sema::LookupTemplateName(LookupResult &Found,
296
305
} else {
297
306
// Perform unqualified name lookup in the current scope.
298
307
LookupName (Found, S);
308
+
309
+ if (!ObjectType.isNull ())
310
+ AllowFunctionTemplatesInLookup = false ;
299
311
}
300
312
301
313
if (Found.empty () && !isDependent) {
@@ -335,7 +347,7 @@ void Sema::LookupTemplateName(LookupResult &Found,
335
347
}
336
348
}
337
349
338
- FilterAcceptableTemplateNames (Found);
350
+ FilterAcceptableTemplateNames (Found, AllowFunctionTemplatesInLookup );
339
351
if (Found.empty ()) {
340
352
if (isDependent)
341
353
MemberOfUnknownSpecialization = true ;
@@ -351,7 +363,7 @@ void Sema::LookupTemplateName(LookupResult &Found,
351
363
LookupResult FoundOuter (*this , Found.getLookupName (), Found.getNameLoc (),
352
364
LookupOrdinaryName);
353
365
LookupName (FoundOuter, S);
354
- FilterAcceptableTemplateNames (FoundOuter);
366
+ FilterAcceptableTemplateNames (FoundOuter, /* AllowFunctionTemplates= */ false );
355
367
356
368
if (FoundOuter.empty ()) {
357
369
// - if the name is not found, the name found in the class of the
0 commit comments