blob: dd877c16fba79c89573d2c0c22e2c359e65552c8 [file] [log] [blame]
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001//===--------------------- SemaLookup.cpp - Name Lookup ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements name lookup for C, C++, Objective-C, and
11// Objective-C++.
12//
13//===----------------------------------------------------------------------===//
14#include "Sema.h"
Douglas Gregor7176fff2009-01-15 00:26:24 +000015#include "clang/AST/ASTContext.h"
Douglas Gregora8f32e02009-10-06 17:59:45 +000016#include "clang/AST/CXXInheritance.h"
Douglas Gregoreb11cd02009-01-14 22:20:51 +000017#include "clang/AST/Decl.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclObjC.h"
Douglas Gregor42af25f2009-05-11 19:58:34 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregorfa047642009-02-04 00:32:51 +000021#include "clang/AST/Expr.h"
Douglas Gregordaa439a2009-07-08 10:57:20 +000022#include "clang/AST/ExprCXX.h"
Douglas Gregoreb11cd02009-01-14 22:20:51 +000023#include "clang/Parse/DeclSpec.h"
Chris Lattner1b63e4f2009-06-14 01:54:56 +000024#include "clang/Basic/Builtins.h"
Douglas Gregoreb11cd02009-01-14 22:20:51 +000025#include "clang/Basic/LangOptions.h"
26#include "llvm/ADT/STLExtras.h"
Douglas Gregorfa047642009-02-04 00:32:51 +000027#include "llvm/ADT/SmallPtrSet.h"
John McCall6e247262009-10-10 05:48:19 +000028#include "llvm/Support/ErrorHandling.h"
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +000029#include <set>
Douglas Gregor2a3009a2009-02-03 19:21:40 +000030#include <vector>
31#include <iterator>
32#include <utility>
33#include <algorithm>
Douglas Gregoreb11cd02009-01-14 22:20:51 +000034
35using namespace clang;
36
Douglas Gregor2a3009a2009-02-03 19:21:40 +000037typedef llvm::SmallVector<UsingDirectiveDecl*, 4> UsingDirectivesTy;
38typedef llvm::DenseSet<NamespaceDecl*> NamespaceSet;
Douglas Gregor2a3009a2009-02-03 19:21:40 +000039
40/// UsingDirAncestorCompare - Implements strict weak ordering of
41/// UsingDirectives. It orders them by address of its common ancestor.
42struct UsingDirAncestorCompare {
43
44 /// @brief Compares UsingDirectiveDecl common ancestor with DeclContext.
45 bool operator () (UsingDirectiveDecl *U, const DeclContext *Ctx) const {
46 return U->getCommonAncestor() < Ctx;
47 }
48
49 /// @brief Compares UsingDirectiveDecl common ancestor with DeclContext.
50 bool operator () (const DeclContext *Ctx, UsingDirectiveDecl *U) const {
51 return Ctx < U->getCommonAncestor();
52 }
53
54 /// @brief Compares UsingDirectiveDecl common ancestors.
55 bool operator () (UsingDirectiveDecl *U1, UsingDirectiveDecl *U2) const {
56 return U1->getCommonAncestor() < U2->getCommonAncestor();
57 }
58};
59
60/// AddNamespaceUsingDirectives - Adds all UsingDirectiveDecl's to heap UDirs
61/// (ordered by common ancestors), found in namespace NS,
62/// including all found (recursively) in their nominated namespaces.
Mike Stump1eb44332009-09-09 15:08:12 +000063void AddNamespaceUsingDirectives(ASTContext &Context,
Douglas Gregor6ab35242009-04-09 21:40:53 +000064 DeclContext *NS,
Douglas Gregor2a3009a2009-02-03 19:21:40 +000065 UsingDirectivesTy &UDirs,
66 NamespaceSet &Visited) {
67 DeclContext::udir_iterator I, End;
68
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000069 for (llvm::tie(I, End) = NS->getUsingDirectives(); I !=End; ++I) {
Douglas Gregor2a3009a2009-02-03 19:21:40 +000070 UDirs.push_back(*I);
71 std::push_heap(UDirs.begin(), UDirs.end(), UsingDirAncestorCompare());
72 NamespaceDecl *Nominated = (*I)->getNominatedNamespace();
73 if (Visited.insert(Nominated).second)
Douglas Gregor6ab35242009-04-09 21:40:53 +000074 AddNamespaceUsingDirectives(Context, Nominated, UDirs, /*ref*/ Visited);
Douglas Gregor2a3009a2009-02-03 19:21:40 +000075 }
76}
77
78/// AddScopeUsingDirectives - Adds all UsingDirectiveDecl's found in Scope S,
79/// including all found in the namespaces they nominate.
Mike Stump1eb44332009-09-09 15:08:12 +000080static void AddScopeUsingDirectives(ASTContext &Context, Scope *S,
Douglas Gregor6ab35242009-04-09 21:40:53 +000081 UsingDirectivesTy &UDirs) {
Douglas Gregor2a3009a2009-02-03 19:21:40 +000082 NamespaceSet VisitedNS;
83
84 if (DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity())) {
85
86 if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(Ctx))
87 VisitedNS.insert(NS);
88
Douglas Gregor6ab35242009-04-09 21:40:53 +000089 AddNamespaceUsingDirectives(Context, Ctx, UDirs, /*ref*/ VisitedNS);
Douglas Gregor2a3009a2009-02-03 19:21:40 +000090
91 } else {
Chris Lattnerb28317a2009-03-28 19:18:32 +000092 Scope::udir_iterator I = S->using_directives_begin(),
93 End = S->using_directives_end();
Douglas Gregor2a3009a2009-02-03 19:21:40 +000094
95 for (; I != End; ++I) {
Chris Lattnerb28317a2009-03-28 19:18:32 +000096 UsingDirectiveDecl *UD = I->getAs<UsingDirectiveDecl>();
Douglas Gregor2a3009a2009-02-03 19:21:40 +000097 UDirs.push_back(UD);
98 std::push_heap(UDirs.begin(), UDirs.end(), UsingDirAncestorCompare());
99
100 NamespaceDecl *Nominated = UD->getNominatedNamespace();
101 if (!VisitedNS.count(Nominated)) {
102 VisitedNS.insert(Nominated);
Mike Stump1eb44332009-09-09 15:08:12 +0000103 AddNamespaceUsingDirectives(Context, Nominated, UDirs,
Douglas Gregor6ab35242009-04-09 21:40:53 +0000104 /*ref*/ VisitedNS);
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000105 }
106 }
107 }
108}
109
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000110// Retrieve the set of identifier namespaces that correspond to a
111// specific kind of name lookup.
Mike Stump1eb44332009-09-09 15:08:12 +0000112inline unsigned
113getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind,
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000114 bool CPlusPlus) {
115 unsigned IDNS = 0;
116 switch (NameKind) {
117 case Sema::LookupOrdinaryName:
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000118 case Sema::LookupOperatorName:
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000119 case Sema::LookupRedeclarationWithLinkage:
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000120 IDNS = Decl::IDNS_Ordinary;
121 if (CPlusPlus)
122 IDNS |= Decl::IDNS_Tag | Decl::IDNS_Member;
123 break;
124
125 case Sema::LookupTagName:
126 IDNS = Decl::IDNS_Tag;
127 break;
128
129 case Sema::LookupMemberName:
130 IDNS = Decl::IDNS_Member;
131 if (CPlusPlus)
Mike Stump1eb44332009-09-09 15:08:12 +0000132 IDNS |= Decl::IDNS_Tag | Decl::IDNS_Ordinary;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000133 break;
134
135 case Sema::LookupNestedNameSpecifierName:
136 case Sema::LookupNamespaceName:
137 IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Member;
138 break;
Douglas Gregor6e378de2009-04-23 23:18:26 +0000139
Douglas Gregor8fc463a2009-04-24 00:11:27 +0000140 case Sema::LookupObjCProtocolName:
141 IDNS = Decl::IDNS_ObjCProtocol;
142 break;
143
144 case Sema::LookupObjCImplementationName:
145 IDNS = Decl::IDNS_ObjCImplementation;
146 break;
147
148 case Sema::LookupObjCCategoryImplName:
149 IDNS = Decl::IDNS_ObjCCategoryImpl;
Douglas Gregor6e378de2009-04-23 23:18:26 +0000150 break;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000151 }
152 return IDNS;
153}
154
John McCallf36e02d2009-10-09 21:13:30 +0000155// Necessary because CXXBasePaths is not complete in Sema.h
156void Sema::LookupResult::deletePaths(CXXBasePaths *Paths) {
157 delete Paths;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000158}
159
John McCallf36e02d2009-10-09 21:13:30 +0000160void Sema::LookupResult::resolveKind() {
161 unsigned N = Decls.size();
Douglas Gregor69d993a2009-01-17 01:13:24 +0000162
John McCallf36e02d2009-10-09 21:13:30 +0000163 // Fast case: no possible ambiguity.
164 if (N <= 1) return;
165
John McCall6e247262009-10-10 05:48:19 +0000166 // Don't do any extra resolution if we've already resolved as ambiguous.
167 if (Kind == Ambiguous) return;
168
John McCallf36e02d2009-10-09 21:13:30 +0000169 llvm::SmallPtrSet<NamedDecl*, 16> Unique;
170
171 bool Ambiguous = false;
172 bool HasTag = false, HasFunction = false, HasNonFunction = false;
173
174 unsigned UniqueTagIndex = 0;
175
176 unsigned I = 0;
177 while (I < N) {
178 NamedDecl *D = Decls[I];
179 assert(D == D->getUnderlyingDecl());
180
181 NamedDecl *CanonD = cast<NamedDecl>(D->getCanonicalDecl());
182 if (!Unique.insert(CanonD)) {
183 // If it's not unique, pull something off the back (and
184 // continue at this index).
185 Decls[I] = Decls[--N];
186 } else if (isa<UnresolvedUsingDecl>(D)) {
187 // FIXME: proper support for UnresolvedUsingDecls.
188 Decls[I] = Decls[--N];
189 } else {
190 // Otherwise, do some decl type analysis and then continue.
191 if (isa<TagDecl>(D)) {
192 if (HasTag)
193 Ambiguous = true;
194 UniqueTagIndex = I;
195 HasTag = true;
196 } else if (D->isFunctionOrFunctionTemplate()) {
197 HasFunction = true;
198 } else {
199 if (HasNonFunction)
200 Ambiguous = true;
201 HasNonFunction = true;
202 }
203 I++;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000204 }
Mike Stump1eb44332009-09-09 15:08:12 +0000205 }
Douglas Gregor516ff432009-04-24 02:57:34 +0000206
John McCallf36e02d2009-10-09 21:13:30 +0000207 // C++ [basic.scope.hiding]p2:
208 // A class name or enumeration name can be hidden by the name of
209 // an object, function, or enumerator declared in the same
210 // scope. If a class or enumeration name and an object, function,
211 // or enumerator are declared in the same scope (in any order)
212 // with the same name, the class or enumeration name is hidden
213 // wherever the object, function, or enumerator name is visible.
214 // But it's still an error if there are distinct tag types found,
215 // even if they're not visible. (ref?)
216 if (HasTag && !Ambiguous && (HasFunction || HasNonFunction))
217 Decls[UniqueTagIndex] = Decls[--N];
Anders Carlsson8b50d012009-06-26 03:37:05 +0000218
John McCallf36e02d2009-10-09 21:13:30 +0000219 Decls.set_size(N);
Douglas Gregor7176fff2009-01-15 00:26:24 +0000220
John McCallf36e02d2009-10-09 21:13:30 +0000221 if (HasFunction && HasNonFunction)
222 Ambiguous = true;
Douglas Gregor69d993a2009-01-17 01:13:24 +0000223
John McCallf36e02d2009-10-09 21:13:30 +0000224 if (Ambiguous)
John McCall6e247262009-10-10 05:48:19 +0000225 setAmbiguous(LookupResult::AmbiguousReference);
John McCallf36e02d2009-10-09 21:13:30 +0000226 else if (N > 1)
John McCall6e247262009-10-10 05:48:19 +0000227 Kind = LookupResult::FoundOverloaded;
John McCallf36e02d2009-10-09 21:13:30 +0000228 else
John McCall6e247262009-10-10 05:48:19 +0000229 Kind = LookupResult::Found;
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000230}
231
232/// @brief Converts the result of name lookup into a single (possible
233/// NULL) pointer to a declaration.
234///
235/// The resulting declaration will either be the declaration we found
236/// (if only a single declaration was found), an
237/// OverloadedFunctionDecl (if an overloaded function was found), or
238/// NULL (if no declaration was found). This conversion must not be
Mike Stump1eb44332009-09-09 15:08:12 +0000239/// used anywhere where name lookup could result in an ambiguity.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000240///
241/// The OverloadedFunctionDecl conversion is meant as a stop-gap
242/// solution, since it causes the OverloadedFunctionDecl to be
243/// leaked. FIXME: Eventually, there will be a better way to iterate
244/// over the set of overloaded functions returned by name lookup.
John McCallf36e02d2009-10-09 21:13:30 +0000245NamedDecl *Sema::LookupResult::getAsSingleDecl(ASTContext &C) const {
246 size_t size = Decls.size();
247 if (size == 0) return 0;
248 if (size == 1) return *begin();
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000249
John McCallf36e02d2009-10-09 21:13:30 +0000250 if (isAmbiguous()) return 0;
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000251
John McCallf36e02d2009-10-09 21:13:30 +0000252 iterator I = begin(), E = end();
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000253
John McCallf36e02d2009-10-09 21:13:30 +0000254 OverloadedFunctionDecl *Ovl
255 = OverloadedFunctionDecl::Create(C, (*I)->getDeclContext(),
256 (*I)->getDeclName());
257 for (; I != E; ++I) {
258 NamedDecl *ND = *I;
259 assert(ND->getUnderlyingDecl() == ND
260 && "decls in lookup result should have redirections stripped");
261 assert(ND->isFunctionOrFunctionTemplate());
262 if (isa<FunctionDecl>(ND))
263 Ovl->addOverload(cast<FunctionDecl>(ND));
Douglas Gregor31a19b62009-04-01 21:51:26 +0000264 else
John McCallf36e02d2009-10-09 21:13:30 +0000265 Ovl->addOverload(cast<FunctionTemplateDecl>(ND));
266 // FIXME: UnresolvedUsingDecls.
Douglas Gregor31a19b62009-04-01 21:51:26 +0000267 }
John McCallf36e02d2009-10-09 21:13:30 +0000268
269 return Ovl;
Douglas Gregord8635172009-02-02 21:35:47 +0000270}
271
John McCallf36e02d2009-10-09 21:13:30 +0000272void Sema::LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) {
273 CXXBasePaths::paths_iterator I, E;
274 DeclContext::lookup_iterator DI, DE;
275 for (I = P.begin(), E = P.end(); I != E; ++I)
276 for (llvm::tie(DI,DE) = I->Decls; DI != DE; ++DI)
277 addDecl(*DI);
Douglas Gregor31a19b62009-04-01 21:51:26 +0000278}
279
John McCallf36e02d2009-10-09 21:13:30 +0000280void Sema::LookupResult::setAmbiguousBaseSubobjects(CXXBasePaths &P) {
281 Paths = new CXXBasePaths;
282 Paths->swap(P);
283 addDeclsFromBasePaths(*Paths);
284 resolveKind();
John McCall6e247262009-10-10 05:48:19 +0000285 setAmbiguous(AmbiguousBaseSubobjects);
Douglas Gregord8635172009-02-02 21:35:47 +0000286}
287
John McCallf36e02d2009-10-09 21:13:30 +0000288void Sema::LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) {
289 Paths = new CXXBasePaths;
290 Paths->swap(P);
291 addDeclsFromBasePaths(*Paths);
292 resolveKind();
John McCall6e247262009-10-10 05:48:19 +0000293 setAmbiguous(AmbiguousBaseSubobjectTypes);
John McCallf36e02d2009-10-09 21:13:30 +0000294}
295
296void Sema::LookupResult::print(llvm::raw_ostream &Out) {
297 Out << Decls.size() << " result(s)";
298 if (isAmbiguous()) Out << ", ambiguous";
299 if (Paths) Out << ", base paths present";
300
301 for (iterator I = begin(), E = end(); I != E; ++I) {
302 Out << "\n";
303 (*I)->print(Out, 2);
304 }
305}
306
307// Adds all qualifying matches for a name within a decl context to the
308// given lookup result. Returns true if any matches were found.
309static bool LookupDirect(Sema::LookupResult &R, DeclContext *DC,
310 DeclarationName Name,
311 Sema::LookupNameKind NameKind,
312 unsigned IDNS) {
313 bool Found = false;
314
315 DeclContext::lookup_iterator I, E;
316 for (llvm::tie(I, E) = DC->lookup(Name); I != E; ++I)
317 if (Sema::isAcceptableLookupResult(*I, NameKind, IDNS))
318 R.addDecl(*I), Found = true;
319
320 return Found;
321}
322
323static bool
324CppNamespaceLookup(Sema::LookupResult &R, ASTContext &Context, DeclContext *NS,
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000325 DeclarationName Name, Sema::LookupNameKind NameKind,
John McCallf36e02d2009-10-09 21:13:30 +0000326 unsigned IDNS, UsingDirectivesTy *UDirs = 0) {
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000327
328 assert(NS && NS->isFileContext() && "CppNamespaceLookup() requires namespace!");
329
330 // Perform qualified name lookup into the LookupCtx.
John McCallf36e02d2009-10-09 21:13:30 +0000331 bool Found = LookupDirect(R, NS, Name, NameKind, IDNS);
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000332
333 if (UDirs) {
334 // For each UsingDirectiveDecl, which common ancestor is equal
335 // to NS, we preform qualified name lookup into namespace nominated by it.
336 UsingDirectivesTy::const_iterator UI, UEnd;
337 llvm::tie(UI, UEnd) =
338 std::equal_range(UDirs->begin(), UDirs->end(), NS,
339 UsingDirAncestorCompare());
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000341 for (; UI != UEnd; ++UI)
John McCallf36e02d2009-10-09 21:13:30 +0000342 if (LookupDirect(R, (*UI)->getNominatedNamespace(), Name, NameKind, IDNS))
343 Found = true;
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000344 }
John McCallf36e02d2009-10-09 21:13:30 +0000345
346 R.resolveKind();
347
348 return Found;
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000349}
350
351static bool isNamespaceOrTranslationUnitScope(Scope *S) {
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000352 if (DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity()))
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000353 return Ctx->isFileContext();
354 return false;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000355}
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000356
Douglas Gregore942bbe2009-09-10 16:57:35 +0000357// Find the next outer declaration context corresponding to this scope.
358static DeclContext *findOuterContext(Scope *S) {
359 for (S = S->getParent(); S; S = S->getParent())
360 if (S->getEntity())
361 return static_cast<DeclContext *>(S->getEntity())->getPrimaryContext();
362
363 return 0;
364}
365
John McCallf36e02d2009-10-09 21:13:30 +0000366bool
367Sema::CppLookupName(LookupResult &R, Scope *S, DeclarationName Name,
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000368 LookupNameKind NameKind, bool RedeclarationOnly) {
369 assert(getLangOptions().CPlusPlus &&
370 "Can perform only C++ lookup");
Mike Stump1eb44332009-09-09 15:08:12 +0000371 unsigned IDNS
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000372 = getIdentifierNamespacesFromLookupNameKind(NameKind, /*CPlusPlus*/ true);
John McCall02cace72009-08-28 07:59:38 +0000373
374 // If we're testing for redeclarations, also look in the friend namespaces.
375 if (RedeclarationOnly) {
376 if (IDNS & Decl::IDNS_Tag) IDNS |= Decl::IDNS_TagFriend;
377 if (IDNS & Decl::IDNS_Ordinary) IDNS |= Decl::IDNS_OrdinaryFriend;
378 }
379
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000380 Scope *Initial = S;
Mike Stump1eb44332009-09-09 15:08:12 +0000381 IdentifierResolver::iterator
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000382 I = IdResolver.begin(Name),
383 IEnd = IdResolver.end();
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000384
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000385 // First we lookup local scope.
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000386 // We don't consider using-directives, as per 7.3.4.p1 [namespace.udir]
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000387 // ...During unqualified name lookup (3.4.1), the names appear as if
388 // they were declared in the nearest enclosing namespace which contains
389 // both the using-directive and the nominated namespace.
Eli Friedman33a31382009-08-05 19:21:58 +0000390 // [Note: in this context, "contains" means "contains directly or
Mike Stump1eb44332009-09-09 15:08:12 +0000391 // indirectly".
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000392 //
393 // For example:
394 // namespace A { int i; }
395 // void foo() {
396 // int i;
397 // {
398 // using namespace A;
399 // ++i; // finds local 'i', A::i appears at global scope
400 // }
401 // }
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000402 //
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000403 for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) {
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000404 // Check whether the IdResolver has anything in this scope.
John McCallf36e02d2009-10-09 21:13:30 +0000405 bool Found = false;
Chris Lattnerb28317a2009-03-28 19:18:32 +0000406 for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) {
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000407 if (isAcceptableLookupResult(*I, NameKind, IDNS)) {
John McCallf36e02d2009-10-09 21:13:30 +0000408 Found = true;
409 R.addDecl(*I);
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000410 }
411 }
John McCallf36e02d2009-10-09 21:13:30 +0000412 if (Found) {
413 R.resolveKind();
414 return true;
415 }
416
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000417 if (DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity())) {
Douglas Gregore942bbe2009-09-10 16:57:35 +0000418 DeclContext *OuterCtx = findOuterContext(S);
419 for (; Ctx && Ctx->getPrimaryContext() != OuterCtx;
420 Ctx = Ctx->getLookupParent()) {
421 if (Ctx->isFunctionOrMethod())
422 continue;
423
424 // Perform qualified name lookup into this context.
425 // FIXME: In some cases, we know that every name that could be found by
426 // this qualified name lookup will also be on the identifier chain. For
427 // example, inside a class without any base classes, we never need to
428 // perform qualified lookup because all of the members are on top of the
429 // identifier chain.
John McCallf36e02d2009-10-09 21:13:30 +0000430 if (LookupQualifiedName(R, Ctx, Name, NameKind, RedeclarationOnly))
431 return true;
Douglas Gregor551f48c2009-03-27 04:21:56 +0000432 }
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000433 }
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000434 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000435
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000436 // Collect UsingDirectiveDecls in all scopes, and recursively all
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000437 // nominated namespaces by those using-directives.
Mike Stump390b4cc2009-05-16 07:39:55 +0000438 // UsingDirectives are pushed to heap, in common ancestor pointer value order.
439 // FIXME: Cache this sorted list in Scope structure, and DeclContext, so we
440 // don't build it for each lookup!
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000441 UsingDirectivesTy UDirs;
442 for (Scope *SC = Initial; SC; SC = SC->getParent())
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000443 if (SC->getFlags() & Scope::DeclScope)
Douglas Gregor6ab35242009-04-09 21:40:53 +0000444 AddScopeUsingDirectives(Context, SC, UDirs);
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000445
446 // Sort heapified UsingDirectiveDecls.
Douglas Gregorb738e082009-05-18 22:06:54 +0000447 std::sort_heap(UDirs.begin(), UDirs.end(), UsingDirAncestorCompare());
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000448
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000449 // Lookup namespace scope, and global scope.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000450 // Unqualified name lookup in C++ requires looking into scopes
451 // that aren't strictly lexical, and therefore we walk through the
452 // context as well as walking through the scopes.
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000453
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000454 for (; S; S = S->getParent()) {
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000455 DeclContext *Ctx = static_cast<DeclContext *>(S->getEntity());
Douglas Gregora24eb4e2009-08-24 18:55:03 +0000456 if (Ctx->isTransparentContext())
457 continue;
458
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000459 assert(Ctx && Ctx->isFileContext() &&
460 "We should have been looking only at file context here already.");
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000461
462 // Check whether the IdResolver has anything in this scope.
John McCallf36e02d2009-10-09 21:13:30 +0000463 bool Found = false;
Chris Lattnerb28317a2009-03-28 19:18:32 +0000464 for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) {
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000465 if (isAcceptableLookupResult(*I, NameKind, IDNS)) {
466 // We found something. Look for anything else in our scope
467 // with this same name and in an acceptable identifier
468 // namespace, so that we can construct an overload set if we
469 // need to.
John McCallf36e02d2009-10-09 21:13:30 +0000470 Found = true;
471 R.addDecl(*I);
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000472 }
473 }
474
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000475 // Look into context considering using-directives.
John McCallf36e02d2009-10-09 21:13:30 +0000476 if (CppNamespaceLookup(R, Context, Ctx, Name, NameKind, IDNS, &UDirs))
477 Found = true;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000478
John McCallf36e02d2009-10-09 21:13:30 +0000479 if (Found) {
480 R.resolveKind();
481 return true;
482 }
483
484 if (RedeclarationOnly && !Ctx->isTransparentContext())
485 return false;
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000486 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000487
John McCallf36e02d2009-10-09 21:13:30 +0000488 return !R.empty();
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000489}
490
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000491/// @brief Perform unqualified name lookup starting from a given
492/// scope.
493///
494/// Unqualified name lookup (C++ [basic.lookup.unqual], C99 6.2.1) is
495/// used to find names within the current scope. For example, 'x' in
496/// @code
497/// int x;
498/// int f() {
499/// return x; // unqualified name look finds 'x' in the global scope
500/// }
501/// @endcode
502///
503/// Different lookup criteria can find different names. For example, a
504/// particular scope can have both a struct and a function of the same
505/// name, and each can be found by certain lookup criteria. For more
506/// information about lookup criteria, see the documentation for the
507/// class LookupCriteria.
508///
509/// @param S The scope from which unqualified name lookup will
510/// begin. If the lookup criteria permits, name lookup may also search
511/// in the parent scopes.
512///
513/// @param Name The name of the entity that we are searching for.
514///
Douglas Gregor3e41d602009-02-13 23:20:09 +0000515/// @param Loc If provided, the source location where we're performing
Mike Stump1eb44332009-09-09 15:08:12 +0000516/// name lookup. At present, this is only used to produce diagnostics when
Douglas Gregor3e41d602009-02-13 23:20:09 +0000517/// C library functions (like "malloc") are implicitly declared.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000518///
519/// @returns The result of name lookup, which includes zero or more
520/// declarations and possibly additional information used to diagnose
521/// ambiguities.
John McCallf36e02d2009-10-09 21:13:30 +0000522bool Sema::LookupName(LookupResult &R, Scope *S, DeclarationName Name,
523 LookupNameKind NameKind, bool RedeclarationOnly,
524 bool AllowBuiltinCreation, SourceLocation Loc) {
525 if (!Name) return false;
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000526
527 if (!getLangOptions().CPlusPlus) {
528 // Unqualified name lookup in C/Objective-C is purely lexical, so
529 // search in the declarations attached to the name.
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000530 unsigned IDNS = 0;
531 switch (NameKind) {
532 case Sema::LookupOrdinaryName:
533 IDNS = Decl::IDNS_Ordinary;
534 break;
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000535
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000536 case Sema::LookupTagName:
537 IDNS = Decl::IDNS_Tag;
538 break;
539
540 case Sema::LookupMemberName:
541 IDNS = Decl::IDNS_Member;
542 break;
543
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000544 case Sema::LookupOperatorName:
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000545 case Sema::LookupNestedNameSpecifierName:
546 case Sema::LookupNamespaceName:
547 assert(false && "C does not perform these kinds of name lookup");
548 break;
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000549
550 case Sema::LookupRedeclarationWithLinkage:
551 // Find the nearest non-transparent declaration scope.
552 while (!(S->getFlags() & Scope::DeclScope) ||
Mike Stump1eb44332009-09-09 15:08:12 +0000553 (S->getEntity() &&
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000554 static_cast<DeclContext *>(S->getEntity())
555 ->isTransparentContext()))
556 S = S->getParent();
557 IDNS = Decl::IDNS_Ordinary;
558 break;
Douglas Gregor6e378de2009-04-23 23:18:26 +0000559
Douglas Gregor8fc463a2009-04-24 00:11:27 +0000560 case Sema::LookupObjCProtocolName:
561 IDNS = Decl::IDNS_ObjCProtocol;
562 break;
563
564 case Sema::LookupObjCImplementationName:
565 IDNS = Decl::IDNS_ObjCImplementation;
566 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000567
Douglas Gregor8fc463a2009-04-24 00:11:27 +0000568 case Sema::LookupObjCCategoryImplName:
569 IDNS = Decl::IDNS_ObjCCategoryImpl;
Douglas Gregor6e378de2009-04-23 23:18:26 +0000570 break;
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000571 }
572
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000573 // Scan up the scope chain looking for a decl that matches this
574 // identifier that is in the appropriate namespace. This search
575 // should not take long, as shadowing of names is uncommon, and
576 // deep shadowing is extremely uncommon.
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000577 bool LeftStartingScope = false;
578
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000579 for (IdentifierResolver::iterator I = IdResolver.begin(Name),
Mike Stump1eb44332009-09-09 15:08:12 +0000580 IEnd = IdResolver.end();
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000581 I != IEnd; ++I)
Douglas Gregorf9201e02009-02-11 23:02:49 +0000582 if ((*I)->isInIdentifierNamespace(IDNS)) {
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000583 if (NameKind == LookupRedeclarationWithLinkage) {
584 // Determine whether this (or a previous) declaration is
585 // out-of-scope.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000586 if (!LeftStartingScope && !S->isDeclScope(DeclPtrTy::make(*I)))
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000587 LeftStartingScope = true;
588
589 // If we found something outside of our starting scope that
590 // does not have linkage, skip it.
591 if (LeftStartingScope && !((*I)->hasLinkage()))
592 continue;
593 }
594
John McCallf36e02d2009-10-09 21:13:30 +0000595 R.addDecl(*I);
596
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000597 if ((*I)->getAttr<OverloadableAttr>()) {
Douglas Gregorf9201e02009-02-11 23:02:49 +0000598 // If this declaration has the "overloadable" attribute, we
599 // might have a set of overloaded functions.
600
601 // Figure out what scope the identifier is in.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000602 while (!(S->getFlags() & Scope::DeclScope) ||
603 !S->isDeclScope(DeclPtrTy::make(*I)))
Douglas Gregorf9201e02009-02-11 23:02:49 +0000604 S = S->getParent();
605
606 // Find the last declaration in this scope (with the same
607 // name, naturally).
608 IdentifierResolver::iterator LastI = I;
609 for (++LastI; LastI != IEnd; ++LastI) {
Chris Lattnerb28317a2009-03-28 19:18:32 +0000610 if (!S->isDeclScope(DeclPtrTy::make(*LastI)))
Douglas Gregorf9201e02009-02-11 23:02:49 +0000611 break;
John McCallf36e02d2009-10-09 21:13:30 +0000612 R.addDecl(*LastI);
Douglas Gregorf9201e02009-02-11 23:02:49 +0000613 }
Douglas Gregorf9201e02009-02-11 23:02:49 +0000614 }
615
John McCallf36e02d2009-10-09 21:13:30 +0000616 R.resolveKind();
617
618 return true;
Douglas Gregorf9201e02009-02-11 23:02:49 +0000619 }
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000620 } else {
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000621 // Perform C++ unqualified name lookup.
John McCallf36e02d2009-10-09 21:13:30 +0000622 if (CppLookupName(R, S, Name, NameKind, RedeclarationOnly))
623 return true;
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000624 }
625
626 // If we didn't find a use of this identifier, and if the identifier
627 // corresponds to a compiler builtin, create the decl object for the builtin
628 // now, injecting it into translation unit scope, and return it.
Mike Stump1eb44332009-09-09 15:08:12 +0000629 if (NameKind == LookupOrdinaryName ||
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000630 NameKind == LookupRedeclarationWithLinkage) {
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000631 IdentifierInfo *II = Name.getAsIdentifierInfo();
Douglas Gregor3e41d602009-02-13 23:20:09 +0000632 if (II && AllowBuiltinCreation) {
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000633 // If this is a builtin on this (or all) targets, create the decl.
Douglas Gregor3e41d602009-02-13 23:20:09 +0000634 if (unsigned BuiltinID = II->getBuiltinID()) {
635 // In C++, we don't have any predefined library functions like
636 // 'malloc'. Instead, we'll just error.
Mike Stump1eb44332009-09-09 15:08:12 +0000637 if (getLangOptions().CPlusPlus &&
Douglas Gregor3e41d602009-02-13 23:20:09 +0000638 Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
John McCallf36e02d2009-10-09 21:13:30 +0000639 return false;
Douglas Gregor3e41d602009-02-13 23:20:09 +0000640
John McCallf36e02d2009-10-09 21:13:30 +0000641 NamedDecl *D = LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID,
642 S, RedeclarationOnly, Loc);
643 if (D) R.addDecl(D);
644 return (D != NULL);
Douglas Gregor3e41d602009-02-13 23:20:09 +0000645 }
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000646 }
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000647 }
John McCallf36e02d2009-10-09 21:13:30 +0000648 return false;
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000649}
650
John McCall6e247262009-10-10 05:48:19 +0000651/// @brief Perform qualified name lookup in the namespaces nominated by
652/// using directives by the given context.
653///
654/// C++98 [namespace.qual]p2:
655/// Given X::m (where X is a user-declared namespace), or given ::m
656/// (where X is the global namespace), let S be the set of all
657/// declarations of m in X and in the transitive closure of all
658/// namespaces nominated by using-directives in X and its used
659/// namespaces, except that using-directives are ignored in any
660/// namespace, including X, directly containing one or more
661/// declarations of m. No namespace is searched more than once in
662/// the lookup of a name. If S is the empty set, the program is
663/// ill-formed. Otherwise, if S has exactly one member, or if the
664/// context of the reference is a using-declaration
665/// (namespace.udecl), S is the required set of declarations of
666/// m. Otherwise if the use of m is not one that allows a unique
667/// declaration to be chosen from S, the program is ill-formed.
668/// C++98 [namespace.qual]p5:
669/// During the lookup of a qualified namespace member name, if the
670/// lookup finds more than one declaration of the member, and if one
671/// declaration introduces a class name or enumeration name and the
672/// other declarations either introduce the same object, the same
673/// enumerator or a set of functions, the non-type name hides the
674/// class or enumeration name if and only if the declarations are
675/// from the same namespace; otherwise (the declarations are from
676/// different namespaces), the program is ill-formed.
677static bool LookupQualifiedNameInUsingDirectives(Sema::LookupResult &R,
678 DeclContext *StartDC,
679 DeclarationName Name,
680 Sema::LookupNameKind NameKind,
681 unsigned IDNS) {
682 assert(StartDC->isFileContext() && "start context is not a file context");
683
684 DeclContext::udir_iterator I = StartDC->using_directives_begin();
685 DeclContext::udir_iterator E = StartDC->using_directives_end();
686
687 if (I == E) return false;
688
689 // We have at least added all these contexts to the queue.
690 llvm::DenseSet<DeclContext*> Visited;
691 Visited.insert(StartDC);
692
693 // We have not yet looked into these namespaces, much less added
694 // their "using-children" to the queue.
695 llvm::SmallVector<NamespaceDecl*, 8> Queue;
696
697 // We have already looked into the initial namespace; seed the queue
698 // with its using-children.
699 for (; I != E; ++I) {
700 NamespaceDecl *ND = (*I)->getNominatedNamespace();
701 if (Visited.insert(ND).second)
702 Queue.push_back(ND);
703 }
704
705 // The easiest way to implement the restriction in [namespace.qual]p5
706 // is to check whether any of the individual results found a tag
707 // and, if so, to declare an ambiguity if the final result is not
708 // a tag.
709 bool FoundTag = false;
710 bool FoundNonTag = false;
711
712 Sema::LookupResult LocalR;
713
714 bool Found = false;
715 while (!Queue.empty()) {
716 NamespaceDecl *ND = Queue.back();
717 Queue.pop_back();
718
719 // We go through some convolutions here to avoid copying results
720 // between LookupResults.
721 bool UseLocal = !R.empty();
722 Sema::LookupResult &DirectR = UseLocal ? LocalR : R;
723 bool FoundDirect = LookupDirect(DirectR, ND, Name, NameKind, IDNS);
724
725 if (FoundDirect) {
726 // First do any local hiding.
727 DirectR.resolveKind();
728
729 // If the local result is a tag, remember that.
730 if (DirectR.isSingleTagDecl())
731 FoundTag = true;
732 else
733 FoundNonTag = true;
734
735 // Append the local results to the total results if necessary.
736 if (UseLocal) {
737 R.addAllDecls(LocalR);
738 LocalR.clear();
739 }
740 }
741
742 // If we find names in this namespace, ignore its using directives.
743 if (FoundDirect) {
744 Found = true;
745 continue;
746 }
747
748 for (llvm::tie(I,E) = ND->getUsingDirectives(); I != E; ++I) {
749 NamespaceDecl *Nom = (*I)->getNominatedNamespace();
750 if (Visited.insert(Nom).second)
751 Queue.push_back(Nom);
752 }
753 }
754
755 if (Found) {
756 if (FoundTag && FoundNonTag)
757 R.setAmbiguousQualifiedTagHiding();
758 else
759 R.resolveKind();
760 }
761
762 return Found;
763}
764
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000765/// @brief Perform qualified name lookup into a given context.
766///
767/// Qualified name lookup (C++ [basic.lookup.qual]) is used to find
768/// names when the context of those names is explicit specified, e.g.,
769/// "std::vector" or "x->member".
770///
771/// Different lookup criteria can find different names. For example, a
772/// particular scope can have both a struct and a function of the same
773/// name, and each can be found by certain lookup criteria. For more
774/// information about lookup criteria, see the documentation for the
775/// class LookupCriteria.
776///
777/// @param LookupCtx The context in which qualified name lookup will
778/// search. If the lookup criteria permits, name lookup may also search
779/// in the parent contexts or (for C++ classes) base classes.
780///
781/// @param Name The name of the entity that we are searching for.
782///
783/// @param Criteria The criteria that this routine will use to
784/// determine which names are visible and which names will be
785/// found. Note that name lookup will find a name that is visible by
786/// the given criteria, but the entity itself may not be semantically
787/// correct or even the kind of entity expected based on the
788/// lookup. For example, searching for a nested-name-specifier name
789/// might result in an EnumDecl, which is visible but is not permitted
790/// as a nested-name-specifier in C++03.
791///
792/// @returns The result of name lookup, which includes zero or more
793/// declarations and possibly additional information used to diagnose
794/// ambiguities.
John McCallf36e02d2009-10-09 21:13:30 +0000795bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
796 DeclarationName Name, LookupNameKind NameKind,
797 bool RedeclarationOnly) {
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000798 assert(LookupCtx && "Sema::LookupQualifiedName requires a lookup context");
Mike Stump1eb44332009-09-09 15:08:12 +0000799
800 if (!Name)
John McCallf36e02d2009-10-09 21:13:30 +0000801 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000802
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000803 // If we're performing qualified name lookup (e.g., lookup into a
804 // struct), find fields as part of ordinary name lookup.
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000805 unsigned IDNS
Mike Stump1eb44332009-09-09 15:08:12 +0000806 = getIdentifierNamespacesFromLookupNameKind(NameKind,
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000807 getLangOptions().CPlusPlus);
808 if (NameKind == LookupOrdinaryName)
809 IDNS |= Decl::IDNS_Member;
Mike Stump1eb44332009-09-09 15:08:12 +0000810
Douglas Gregor2dd078a2009-09-02 22:59:36 +0000811 // Make sure that the declaration context is complete.
812 assert((!isa<TagDecl>(LookupCtx) ||
813 LookupCtx->isDependentContext() ||
814 cast<TagDecl>(LookupCtx)->isDefinition() ||
815 Context.getTypeDeclType(cast<TagDecl>(LookupCtx))->getAs<TagType>()
816 ->isBeingDefined()) &&
817 "Declaration context must already be complete!");
Mike Stump1eb44332009-09-09 15:08:12 +0000818
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000819 // Perform qualified name lookup into the LookupCtx.
John McCallf36e02d2009-10-09 21:13:30 +0000820 if (LookupDirect(R, LookupCtx, Name, NameKind, IDNS)) {
821 R.resolveKind();
822 return true;
823 }
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000824
John McCall6e247262009-10-10 05:48:19 +0000825 // Don't descend into implied contexts for redeclarations.
826 // C++98 [namespace.qual]p6:
827 // In a declaration for a namespace member in which the
828 // declarator-id is a qualified-id, given that the qualified-id
829 // for the namespace member has the form
830 // nested-name-specifier unqualified-id
831 // the unqualified-id shall name a member of the namespace
832 // designated by the nested-name-specifier.
833 // See also [class.mfct]p5 and [class.static.data]p2.
834 if (RedeclarationOnly)
835 return false;
836
837 // If this is a namespace, look it up in
838 if (LookupCtx->isFileContext())
839 return LookupQualifiedNameInUsingDirectives(R, LookupCtx, Name, NameKind,
840 IDNS);
841
Douglas Gregor2dd078a2009-09-02 22:59:36 +0000842 // If this isn't a C++ class, we aren't allowed to look into base
Douglas Gregor4719f4e2009-09-11 22:57:37 +0000843 // classes, we're done.
John McCall6e247262009-10-10 05:48:19 +0000844 if (!isa<CXXRecordDecl>(LookupCtx))
John McCallf36e02d2009-10-09 21:13:30 +0000845 return false;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000846
847 // Perform lookup into our base classes.
Douglas Gregora8f32e02009-10-06 17:59:45 +0000848 CXXRecordDecl *LookupRec = cast<CXXRecordDecl>(LookupCtx);
849 CXXBasePaths Paths;
850 Paths.setOrigin(LookupRec);
Douglas Gregor7176fff2009-01-15 00:26:24 +0000851
852 // Look for this member in our base classes
Douglas Gregora8f32e02009-10-06 17:59:45 +0000853 CXXRecordDecl::BaseMatchesCallback *BaseCallback = 0;
854 switch (NameKind) {
855 case LookupOrdinaryName:
856 case LookupMemberName:
857 case LookupRedeclarationWithLinkage:
858 BaseCallback = &CXXRecordDecl::FindOrdinaryMember;
859 break;
860
861 case LookupTagName:
862 BaseCallback = &CXXRecordDecl::FindTagMember;
863 break;
864
865 case LookupOperatorName:
866 case LookupNamespaceName:
867 case LookupObjCProtocolName:
868 case LookupObjCImplementationName:
869 case LookupObjCCategoryImplName:
870 // These lookups will never find a member in a C++ class (or base class).
John McCallf36e02d2009-10-09 21:13:30 +0000871 return false;
Douglas Gregora8f32e02009-10-06 17:59:45 +0000872
873 case LookupNestedNameSpecifierName:
874 BaseCallback = &CXXRecordDecl::FindNestedNameSpecifierMember;
875 break;
876 }
877
878 if (!LookupRec->lookupInBases(BaseCallback, Name.getAsOpaquePtr(), Paths))
John McCallf36e02d2009-10-09 21:13:30 +0000879 return false;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000880
881 // C++ [class.member.lookup]p2:
882 // [...] If the resulting set of declarations are not all from
883 // sub-objects of the same type, or the set has a nonstatic member
884 // and includes members from distinct sub-objects, there is an
885 // ambiguity and the program is ill-formed. Otherwise that set is
886 // the result of the lookup.
887 // FIXME: support using declarations!
888 QualType SubobjectType;
Daniel Dunbarf1853192009-01-15 18:32:35 +0000889 int SubobjectNumber = 0;
Douglas Gregora8f32e02009-10-06 17:59:45 +0000890 for (CXXBasePaths::paths_iterator Path = Paths.begin(), PathEnd = Paths.end();
Douglas Gregor7176fff2009-01-15 00:26:24 +0000891 Path != PathEnd; ++Path) {
Douglas Gregora8f32e02009-10-06 17:59:45 +0000892 const CXXBasePathElement &PathElement = Path->back();
Douglas Gregor7176fff2009-01-15 00:26:24 +0000893
894 // Determine whether we're looking at a distinct sub-object or not.
895 if (SubobjectType.isNull()) {
John McCallf36e02d2009-10-09 21:13:30 +0000896 // This is the first subobject we've looked at. Record its type.
Douglas Gregor7176fff2009-01-15 00:26:24 +0000897 SubobjectType = Context.getCanonicalType(PathElement.Base->getType());
898 SubobjectNumber = PathElement.SubobjectNumber;
Mike Stump1eb44332009-09-09 15:08:12 +0000899 } else if (SubobjectType
Douglas Gregor7176fff2009-01-15 00:26:24 +0000900 != Context.getCanonicalType(PathElement.Base->getType())) {
901 // We found members of the given name in two subobjects of
902 // different types. This lookup is ambiguous.
John McCallf36e02d2009-10-09 21:13:30 +0000903 R.setAmbiguousBaseSubobjectTypes(Paths);
904 return true;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000905 } else if (SubobjectNumber != PathElement.SubobjectNumber) {
906 // We have a different subobject of the same type.
907
908 // C++ [class.member.lookup]p5:
909 // A static member, a nested type or an enumerator defined in
910 // a base class T can unambiguously be found even if an object
Mike Stump1eb44332009-09-09 15:08:12 +0000911 // has more than one base class subobject of type T.
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000912 Decl *FirstDecl = *Path->Decls.first;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000913 if (isa<VarDecl>(FirstDecl) ||
914 isa<TypeDecl>(FirstDecl) ||
915 isa<EnumConstantDecl>(FirstDecl))
916 continue;
917
918 if (isa<CXXMethodDecl>(FirstDecl)) {
919 // Determine whether all of the methods are static.
920 bool AllMethodsAreStatic = true;
921 for (DeclContext::lookup_iterator Func = Path->Decls.first;
922 Func != Path->Decls.second; ++Func) {
923 if (!isa<CXXMethodDecl>(*Func)) {
924 assert(isa<TagDecl>(*Func) && "Non-function must be a tag decl");
925 break;
926 }
927
928 if (!cast<CXXMethodDecl>(*Func)->isStatic()) {
929 AllMethodsAreStatic = false;
930 break;
931 }
932 }
933
934 if (AllMethodsAreStatic)
935 continue;
936 }
937
938 // We have found a nonstatic member name in multiple, distinct
939 // subobjects. Name lookup is ambiguous.
John McCallf36e02d2009-10-09 21:13:30 +0000940 R.setAmbiguousBaseSubobjects(Paths);
941 return true;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000942 }
943 }
944
945 // Lookup in a base class succeeded; return these results.
946
John McCallf36e02d2009-10-09 21:13:30 +0000947 DeclContext::lookup_iterator I, E;
948 for (llvm::tie(I,E) = Paths.front().Decls; I != E; ++I)
949 R.addDecl(*I);
950 R.resolveKind();
951 return true;
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000952}
953
954/// @brief Performs name lookup for a name that was parsed in the
955/// source code, and may contain a C++ scope specifier.
956///
957/// This routine is a convenience routine meant to be called from
958/// contexts that receive a name and an optional C++ scope specifier
959/// (e.g., "N::M::x"). It will then perform either qualified or
960/// unqualified name lookup (with LookupQualifiedName or LookupName,
961/// respectively) on the given name and return those results.
962///
963/// @param S The scope from which unqualified name lookup will
964/// begin.
Mike Stump1eb44332009-09-09 15:08:12 +0000965///
Douglas Gregor495c35d2009-08-25 22:51:20 +0000966/// @param SS An optional C++ scope-specifier, e.g., "::N::M".
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000967///
968/// @param Name The name of the entity that name lookup will
969/// search for.
970///
Douglas Gregor3e41d602009-02-13 23:20:09 +0000971/// @param Loc If provided, the source location where we're performing
Mike Stump1eb44332009-09-09 15:08:12 +0000972/// name lookup. At present, this is only used to produce diagnostics when
Douglas Gregor3e41d602009-02-13 23:20:09 +0000973/// C library functions (like "malloc") are implicitly declared.
974///
Douglas Gregor495c35d2009-08-25 22:51:20 +0000975/// @param EnteringContext Indicates whether we are going to enter the
976/// context of the scope-specifier SS (if present).
977///
John McCallf36e02d2009-10-09 21:13:30 +0000978/// @returns True if any decls were found (but possibly ambiguous)
979bool Sema::LookupParsedName(LookupResult &R, Scope *S, const CXXScopeSpec *SS,
980 DeclarationName Name, LookupNameKind NameKind,
981 bool RedeclarationOnly, bool AllowBuiltinCreation,
982 SourceLocation Loc,
983 bool EnteringContext) {
Douglas Gregor495c35d2009-08-25 22:51:20 +0000984 if (SS && SS->isInvalid()) {
985 // When the scope specifier is invalid, don't even look for
Douglas Gregor42af25f2009-05-11 19:58:34 +0000986 // anything.
John McCallf36e02d2009-10-09 21:13:30 +0000987 return false;
Douglas Gregor495c35d2009-08-25 22:51:20 +0000988 }
Mike Stump1eb44332009-09-09 15:08:12 +0000989
Douglas Gregor495c35d2009-08-25 22:51:20 +0000990 if (SS && SS->isSet()) {
991 if (DeclContext *DC = computeDeclContext(*SS, EnteringContext)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000992 // We have resolved the scope specifier to a particular declaration
Douglas Gregor495c35d2009-08-25 22:51:20 +0000993 // contex, and will perform name lookup in that context.
Douglas Gregor2dd078a2009-09-02 22:59:36 +0000994 if (!DC->isDependentContext() && RequireCompleteDeclContext(*SS))
John McCallf36e02d2009-10-09 21:13:30 +0000995 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000996
John McCallf36e02d2009-10-09 21:13:30 +0000997 return LookupQualifiedName(R, DC, Name, NameKind, RedeclarationOnly);
Douglas Gregore4e5b052009-03-19 00:18:19 +0000998 }
Douglas Gregor42af25f2009-05-11 19:58:34 +0000999
Douglas Gregor495c35d2009-08-25 22:51:20 +00001000 // We could not resolve the scope specified to a specific declaration
Mike Stump1eb44332009-09-09 15:08:12 +00001001 // context, which means that SS refers to an unknown specialization.
Douglas Gregor495c35d2009-08-25 22:51:20 +00001002 // Name lookup can't find anything in this case.
John McCallf36e02d2009-10-09 21:13:30 +00001003 return false;
Douglas Gregor4c921ae2009-01-30 01:04:22 +00001004 }
1005
Mike Stump1eb44332009-09-09 15:08:12 +00001006 // Perform unqualified name lookup starting in the given scope.
John McCallf36e02d2009-10-09 21:13:30 +00001007 return LookupName(R, S, Name, NameKind, RedeclarationOnly,
1008 AllowBuiltinCreation, Loc);
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001009}
1010
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001011
Douglas Gregor7176fff2009-01-15 00:26:24 +00001012/// @brief Produce a diagnostic describing the ambiguity that resulted
1013/// from name lookup.
1014///
1015/// @param Result The ambiguous name lookup result.
Mike Stump1eb44332009-09-09 15:08:12 +00001016///
Douglas Gregor7176fff2009-01-15 00:26:24 +00001017/// @param Name The name of the entity that name lookup was
1018/// searching for.
1019///
1020/// @param NameLoc The location of the name within the source code.
1021///
1022/// @param LookupRange A source range that provides more
1023/// source-location information concerning the lookup itself. For
1024/// example, this range might highlight a nested-name-specifier that
1025/// precedes the name.
1026///
1027/// @returns true
1028bool Sema::DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
Mike Stump1eb44332009-09-09 15:08:12 +00001029 SourceLocation NameLoc,
Douglas Gregor7176fff2009-01-15 00:26:24 +00001030 SourceRange LookupRange) {
1031 assert(Result.isAmbiguous() && "Lookup result must be ambiguous");
1032
John McCall6e247262009-10-10 05:48:19 +00001033 switch (Result.getAmbiguityKind()) {
1034 case LookupResult::AmbiguousBaseSubobjects: {
1035 CXXBasePaths *Paths = Result.getBasePaths();
1036 QualType SubobjectType = Paths->front().back().Base->getType();
1037 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobjects)
1038 << Name << SubobjectType << getAmbiguousPathsDisplayString(*Paths)
1039 << LookupRange;
1040
1041 DeclContext::lookup_iterator Found = Paths->front().Decls.first;
1042 while (isa<CXXMethodDecl>(*Found) &&
1043 cast<CXXMethodDecl>(*Found)->isStatic())
1044 ++Found;
1045
1046 Diag((*Found)->getLocation(), diag::note_ambiguous_member_found);
1047
1048 return true;
1049 }
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +00001050
John McCall6e247262009-10-10 05:48:19 +00001051 case LookupResult::AmbiguousBaseSubobjectTypes: {
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001052 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types)
1053 << Name << LookupRange;
John McCall6e247262009-10-10 05:48:19 +00001054
1055 CXXBasePaths *Paths = Result.getBasePaths();
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001056 std::set<Decl *> DeclsPrinted;
John McCall6e247262009-10-10 05:48:19 +00001057 for (CXXBasePaths::paths_iterator Path = Paths->begin(),
1058 PathEnd = Paths->end();
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001059 Path != PathEnd; ++Path) {
1060 Decl *D = *Path->Decls.first;
1061 if (DeclsPrinted.insert(D).second)
1062 Diag(D->getLocation(), diag::note_ambiguous_member_found);
1063 }
1064
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +00001065 return true;
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +00001066 }
1067
John McCall6e247262009-10-10 05:48:19 +00001068 case LookupResult::AmbiguousTagHiding: {
1069 Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange;
Douglas Gregor69d993a2009-01-17 01:13:24 +00001070
John McCall6e247262009-10-10 05:48:19 +00001071 llvm::SmallPtrSet<NamedDecl*,8> TagDecls;
1072
1073 LookupResult::iterator DI, DE = Result.end();
1074 for (DI = Result.begin(); DI != DE; ++DI)
1075 if (TagDecl *TD = dyn_cast<TagDecl>(*DI)) {
1076 TagDecls.insert(TD);
1077 Diag(TD->getLocation(), diag::note_hidden_tag);
1078 }
1079
1080 for (DI = Result.begin(); DI != DE; ++DI)
1081 if (!isa<TagDecl>(*DI))
1082 Diag((*DI)->getLocation(), diag::note_hiding_object);
1083
1084 // For recovery purposes, go ahead and implement the hiding.
1085 Result.hideDecls(TagDecls);
1086
1087 return true;
1088 }
1089
1090 case LookupResult::AmbiguousReference: {
1091 Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange;
John McCallf36e02d2009-10-09 21:13:30 +00001092
John McCall6e247262009-10-10 05:48:19 +00001093 LookupResult::iterator DI = Result.begin(), DE = Result.end();
1094 for (; DI != DE; ++DI)
1095 Diag((*DI)->getLocation(), diag::note_ambiguous_candidate) << *DI;
John McCallf36e02d2009-10-09 21:13:30 +00001096
John McCall6e247262009-10-10 05:48:19 +00001097 return true;
1098 }
1099 }
1100
1101 llvm::llvm_unreachable("unknown ambiguity kind");
Douglas Gregor7176fff2009-01-15 00:26:24 +00001102 return true;
1103}
Douglas Gregorfa047642009-02-04 00:32:51 +00001104
Mike Stump1eb44332009-09-09 15:08:12 +00001105static void
1106addAssociatedClassesAndNamespaces(QualType T,
Douglas Gregor69be8d62009-07-08 07:51:57 +00001107 ASTContext &Context,
1108 Sema::AssociatedNamespaceSet &AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001109 Sema::AssociatedClassSet &AssociatedClasses);
1110
1111static void CollectNamespace(Sema::AssociatedNamespaceSet &Namespaces,
1112 DeclContext *Ctx) {
1113 if (Ctx->isFileContext())
1114 Namespaces.insert(Ctx);
1115}
Douglas Gregor69be8d62009-07-08 07:51:57 +00001116
Mike Stump1eb44332009-09-09 15:08:12 +00001117// \brief Add the associated classes and namespaces for argument-dependent
Douglas Gregor69be8d62009-07-08 07:51:57 +00001118// lookup that involves a template argument (C++ [basic.lookup.koenig]p2).
Mike Stump1eb44332009-09-09 15:08:12 +00001119static void
1120addAssociatedClassesAndNamespaces(const TemplateArgument &Arg,
Douglas Gregor69be8d62009-07-08 07:51:57 +00001121 ASTContext &Context,
1122 Sema::AssociatedNamespaceSet &AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001123 Sema::AssociatedClassSet &AssociatedClasses) {
Douglas Gregor69be8d62009-07-08 07:51:57 +00001124 // C++ [basic.lookup.koenig]p2, last bullet:
Mike Stump1eb44332009-09-09 15:08:12 +00001125 // -- [...] ;
Douglas Gregor69be8d62009-07-08 07:51:57 +00001126 switch (Arg.getKind()) {
1127 case TemplateArgument::Null:
1128 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001129
Douglas Gregor69be8d62009-07-08 07:51:57 +00001130 case TemplateArgument::Type:
1131 // [...] the namespaces and classes associated with the types of the
1132 // template arguments provided for template type parameters (excluding
1133 // template template parameters)
1134 addAssociatedClassesAndNamespaces(Arg.getAsType(), Context,
1135 AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001136 AssociatedClasses);
Douglas Gregor69be8d62009-07-08 07:51:57 +00001137 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001138
Douglas Gregor69be8d62009-07-08 07:51:57 +00001139 case TemplateArgument::Declaration:
Mike Stump1eb44332009-09-09 15:08:12 +00001140 // [...] the namespaces in which any template template arguments are
1141 // defined; and the classes in which any member templates used as
Douglas Gregor69be8d62009-07-08 07:51:57 +00001142 // template template arguments are defined.
Mike Stump1eb44332009-09-09 15:08:12 +00001143 if (ClassTemplateDecl *ClassTemplate
Douglas Gregor69be8d62009-07-08 07:51:57 +00001144 = dyn_cast<ClassTemplateDecl>(Arg.getAsDecl())) {
1145 DeclContext *Ctx = ClassTemplate->getDeclContext();
1146 if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
1147 AssociatedClasses.insert(EnclosingClass);
1148 // Add the associated namespace for this class.
1149 while (Ctx->isRecord())
1150 Ctx = Ctx->getParent();
John McCall6ff07852009-08-07 22:18:02 +00001151 CollectNamespace(AssociatedNamespaces, Ctx);
Douglas Gregor69be8d62009-07-08 07:51:57 +00001152 }
1153 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Douglas Gregor69be8d62009-07-08 07:51:57 +00001155 case TemplateArgument::Integral:
1156 case TemplateArgument::Expression:
Mike Stump1eb44332009-09-09 15:08:12 +00001157 // [Note: non-type template arguments do not contribute to the set of
Douglas Gregor69be8d62009-07-08 07:51:57 +00001158 // associated namespaces. ]
1159 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Douglas Gregor69be8d62009-07-08 07:51:57 +00001161 case TemplateArgument::Pack:
1162 for (TemplateArgument::pack_iterator P = Arg.pack_begin(),
1163 PEnd = Arg.pack_end();
1164 P != PEnd; ++P)
1165 addAssociatedClassesAndNamespaces(*P, Context,
1166 AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001167 AssociatedClasses);
Douglas Gregor69be8d62009-07-08 07:51:57 +00001168 break;
1169 }
1170}
1171
Douglas Gregorfa047642009-02-04 00:32:51 +00001172// \brief Add the associated classes and namespaces for
Mike Stump1eb44332009-09-09 15:08:12 +00001173// argument-dependent lookup with an argument of class type
1174// (C++ [basic.lookup.koenig]p2).
1175static void
1176addAssociatedClassesAndNamespaces(CXXRecordDecl *Class,
Douglas Gregorfa047642009-02-04 00:32:51 +00001177 ASTContext &Context,
1178 Sema::AssociatedNamespaceSet &AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001179 Sema::AssociatedClassSet &AssociatedClasses) {
Douglas Gregorfa047642009-02-04 00:32:51 +00001180 // C++ [basic.lookup.koenig]p2:
1181 // [...]
1182 // -- If T is a class type (including unions), its associated
1183 // classes are: the class itself; the class of which it is a
1184 // member, if any; and its direct and indirect base
1185 // classes. Its associated namespaces are the namespaces in
Mike Stump1eb44332009-09-09 15:08:12 +00001186 // which its associated classes are defined.
Douglas Gregorfa047642009-02-04 00:32:51 +00001187
1188 // Add the class of which it is a member, if any.
1189 DeclContext *Ctx = Class->getDeclContext();
1190 if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
1191 AssociatedClasses.insert(EnclosingClass);
Douglas Gregorfa047642009-02-04 00:32:51 +00001192 // Add the associated namespace for this class.
1193 while (Ctx->isRecord())
1194 Ctx = Ctx->getParent();
John McCall6ff07852009-08-07 22:18:02 +00001195 CollectNamespace(AssociatedNamespaces, Ctx);
Mike Stump1eb44332009-09-09 15:08:12 +00001196
Douglas Gregorfa047642009-02-04 00:32:51 +00001197 // Add the class itself. If we've already seen this class, we don't
1198 // need to visit base classes.
1199 if (!AssociatedClasses.insert(Class))
1200 return;
1201
Mike Stump1eb44332009-09-09 15:08:12 +00001202 // -- If T is a template-id, its associated namespaces and classes are
1203 // the namespace in which the template is defined; for member
Douglas Gregor69be8d62009-07-08 07:51:57 +00001204 // templates, the member template’s class; the namespaces and classes
Mike Stump1eb44332009-09-09 15:08:12 +00001205 // associated with the types of the template arguments provided for
Douglas Gregor69be8d62009-07-08 07:51:57 +00001206 // template type parameters (excluding template template parameters); the
Mike Stump1eb44332009-09-09 15:08:12 +00001207 // namespaces in which any template template arguments are defined; and
1208 // the classes in which any member templates used as template template
1209 // arguments are defined. [Note: non-type template arguments do not
Douglas Gregor69be8d62009-07-08 07:51:57 +00001210 // contribute to the set of associated namespaces. ]
Mike Stump1eb44332009-09-09 15:08:12 +00001211 if (ClassTemplateSpecializationDecl *Spec
Douglas Gregor69be8d62009-07-08 07:51:57 +00001212 = dyn_cast<ClassTemplateSpecializationDecl>(Class)) {
1213 DeclContext *Ctx = Spec->getSpecializedTemplate()->getDeclContext();
1214 if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
1215 AssociatedClasses.insert(EnclosingClass);
1216 // Add the associated namespace for this class.
1217 while (Ctx->isRecord())
1218 Ctx = Ctx->getParent();
John McCall6ff07852009-08-07 22:18:02 +00001219 CollectNamespace(AssociatedNamespaces, Ctx);
Mike Stump1eb44332009-09-09 15:08:12 +00001220
Douglas Gregor69be8d62009-07-08 07:51:57 +00001221 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1222 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
1223 addAssociatedClassesAndNamespaces(TemplateArgs[I], Context,
1224 AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001225 AssociatedClasses);
Douglas Gregor69be8d62009-07-08 07:51:57 +00001226 }
Mike Stump1eb44332009-09-09 15:08:12 +00001227
Douglas Gregorfa047642009-02-04 00:32:51 +00001228 // Add direct and indirect base classes along with their associated
1229 // namespaces.
1230 llvm::SmallVector<CXXRecordDecl *, 32> Bases;
1231 Bases.push_back(Class);
1232 while (!Bases.empty()) {
1233 // Pop this class off the stack.
1234 Class = Bases.back();
1235 Bases.pop_back();
1236
1237 // Visit the base classes.
1238 for (CXXRecordDecl::base_class_iterator Base = Class->bases_begin(),
1239 BaseEnd = Class->bases_end();
1240 Base != BaseEnd; ++Base) {
Ted Kremenek6217b802009-07-29 21:53:49 +00001241 const RecordType *BaseType = Base->getType()->getAs<RecordType>();
Douglas Gregorfa047642009-02-04 00:32:51 +00001242 CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(BaseType->getDecl());
1243 if (AssociatedClasses.insert(BaseDecl)) {
1244 // Find the associated namespace for this base class.
1245 DeclContext *BaseCtx = BaseDecl->getDeclContext();
1246 while (BaseCtx->isRecord())
1247 BaseCtx = BaseCtx->getParent();
John McCall6ff07852009-08-07 22:18:02 +00001248 CollectNamespace(AssociatedNamespaces, BaseCtx);
Douglas Gregorfa047642009-02-04 00:32:51 +00001249
1250 // Make sure we visit the bases of this base class.
1251 if (BaseDecl->bases_begin() != BaseDecl->bases_end())
1252 Bases.push_back(BaseDecl);
1253 }
1254 }
1255 }
1256}
1257
1258// \brief Add the associated classes and namespaces for
1259// argument-dependent lookup with an argument of type T
Mike Stump1eb44332009-09-09 15:08:12 +00001260// (C++ [basic.lookup.koenig]p2).
1261static void
1262addAssociatedClassesAndNamespaces(QualType T,
Douglas Gregorfa047642009-02-04 00:32:51 +00001263 ASTContext &Context,
1264 Sema::AssociatedNamespaceSet &AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001265 Sema::AssociatedClassSet &AssociatedClasses) {
Douglas Gregorfa047642009-02-04 00:32:51 +00001266 // C++ [basic.lookup.koenig]p2:
1267 //
1268 // For each argument type T in the function call, there is a set
1269 // of zero or more associated namespaces and a set of zero or more
1270 // associated classes to be considered. The sets of namespaces and
1271 // classes is determined entirely by the types of the function
1272 // arguments (and the namespace of any template template
1273 // argument). Typedef names and using-declarations used to specify
1274 // the types do not contribute to this set. The sets of namespaces
1275 // and classes are determined in the following way:
1276 T = Context.getCanonicalType(T).getUnqualifiedType();
1277
1278 // -- If T is a pointer to U or an array of U, its associated
Mike Stump1eb44332009-09-09 15:08:12 +00001279 // namespaces and classes are those associated with U.
Douglas Gregorfa047642009-02-04 00:32:51 +00001280 //
1281 // We handle this by unwrapping pointer and array types immediately,
1282 // to avoid unnecessary recursion.
1283 while (true) {
Ted Kremenek6217b802009-07-29 21:53:49 +00001284 if (const PointerType *Ptr = T->getAs<PointerType>())
Douglas Gregorfa047642009-02-04 00:32:51 +00001285 T = Ptr->getPointeeType();
1286 else if (const ArrayType *Ptr = Context.getAsArrayType(T))
1287 T = Ptr->getElementType();
Mike Stump1eb44332009-09-09 15:08:12 +00001288 else
Douglas Gregorfa047642009-02-04 00:32:51 +00001289 break;
1290 }
1291
1292 // -- If T is a fundamental type, its associated sets of
1293 // namespaces and classes are both empty.
John McCall183700f2009-09-21 23:43:11 +00001294 if (T->getAs<BuiltinType>())
Douglas Gregorfa047642009-02-04 00:32:51 +00001295 return;
1296
1297 // -- If T is a class type (including unions), its associated
1298 // classes are: the class itself; the class of which it is a
1299 // member, if any; and its direct and indirect base
1300 // classes. Its associated namespaces are the namespaces in
Mike Stump1eb44332009-09-09 15:08:12 +00001301 // which its associated classes are defined.
Ted Kremenek6217b802009-07-29 21:53:49 +00001302 if (const RecordType *ClassType = T->getAs<RecordType>())
Mike Stump1eb44332009-09-09 15:08:12 +00001303 if (CXXRecordDecl *ClassDecl
Douglas Gregorc1efaec2009-02-28 01:32:25 +00001304 = dyn_cast<CXXRecordDecl>(ClassType->getDecl())) {
Mike Stump1eb44332009-09-09 15:08:12 +00001305 addAssociatedClassesAndNamespaces(ClassDecl, Context,
1306 AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001307 AssociatedClasses);
Douglas Gregorc1efaec2009-02-28 01:32:25 +00001308 return;
1309 }
Douglas Gregorfa047642009-02-04 00:32:51 +00001310
1311 // -- If T is an enumeration type, its associated namespace is
1312 // the namespace in which it is defined. If it is class
1313 // member, its associated class is the member’s class; else
Mike Stump1eb44332009-09-09 15:08:12 +00001314 // it has no associated class.
John McCall183700f2009-09-21 23:43:11 +00001315 if (const EnumType *EnumT = T->getAs<EnumType>()) {
Douglas Gregorfa047642009-02-04 00:32:51 +00001316 EnumDecl *Enum = EnumT->getDecl();
1317
1318 DeclContext *Ctx = Enum->getDeclContext();
1319 if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
1320 AssociatedClasses.insert(EnclosingClass);
1321
1322 // Add the associated namespace for this class.
1323 while (Ctx->isRecord())
1324 Ctx = Ctx->getParent();
John McCall6ff07852009-08-07 22:18:02 +00001325 CollectNamespace(AssociatedNamespaces, Ctx);
Douglas Gregorfa047642009-02-04 00:32:51 +00001326
1327 return;
1328 }
1329
1330 // -- If T is a function type, its associated namespaces and
1331 // classes are those associated with the function parameter
1332 // types and those associated with the return type.
John McCall183700f2009-09-21 23:43:11 +00001333 if (const FunctionType *FnType = T->getAs<FunctionType>()) {
Douglas Gregorfa047642009-02-04 00:32:51 +00001334 // Return type
John McCall183700f2009-09-21 23:43:11 +00001335 addAssociatedClassesAndNamespaces(FnType->getResultType(),
Douglas Gregorfa047642009-02-04 00:32:51 +00001336 Context,
John McCall6ff07852009-08-07 22:18:02 +00001337 AssociatedNamespaces, AssociatedClasses);
Douglas Gregorfa047642009-02-04 00:32:51 +00001338
John McCall183700f2009-09-21 23:43:11 +00001339 const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FnType);
Douglas Gregorfa047642009-02-04 00:32:51 +00001340 if (!Proto)
1341 return;
1342
1343 // Argument types
Douglas Gregor72564e72009-02-26 23:50:07 +00001344 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
Mike Stump1eb44332009-09-09 15:08:12 +00001345 ArgEnd = Proto->arg_type_end();
Douglas Gregorfa047642009-02-04 00:32:51 +00001346 Arg != ArgEnd; ++Arg)
1347 addAssociatedClassesAndNamespaces(*Arg, Context,
John McCall6ff07852009-08-07 22:18:02 +00001348 AssociatedNamespaces, AssociatedClasses);
Mike Stump1eb44332009-09-09 15:08:12 +00001349
Douglas Gregorfa047642009-02-04 00:32:51 +00001350 return;
1351 }
1352
1353 // -- If T is a pointer to a member function of a class X, its
1354 // associated namespaces and classes are those associated
1355 // with the function parameter types and return type,
Mike Stump1eb44332009-09-09 15:08:12 +00001356 // together with those associated with X.
Douglas Gregorfa047642009-02-04 00:32:51 +00001357 //
1358 // -- If T is a pointer to a data member of class X, its
1359 // associated namespaces and classes are those associated
1360 // with the member type together with those associated with
Mike Stump1eb44332009-09-09 15:08:12 +00001361 // X.
Ted Kremenek6217b802009-07-29 21:53:49 +00001362 if (const MemberPointerType *MemberPtr = T->getAs<MemberPointerType>()) {
Douglas Gregorfa047642009-02-04 00:32:51 +00001363 // Handle the type that the pointer to member points to.
1364 addAssociatedClassesAndNamespaces(MemberPtr->getPointeeType(),
1365 Context,
John McCall6ff07852009-08-07 22:18:02 +00001366 AssociatedNamespaces,
1367 AssociatedClasses);
Douglas Gregorfa047642009-02-04 00:32:51 +00001368
1369 // Handle the class type into which this points.
Ted Kremenek6217b802009-07-29 21:53:49 +00001370 if (const RecordType *Class = MemberPtr->getClass()->getAs<RecordType>())
Douglas Gregorfa047642009-02-04 00:32:51 +00001371 addAssociatedClassesAndNamespaces(cast<CXXRecordDecl>(Class->getDecl()),
1372 Context,
John McCall6ff07852009-08-07 22:18:02 +00001373 AssociatedNamespaces,
1374 AssociatedClasses);
Douglas Gregorfa047642009-02-04 00:32:51 +00001375
1376 return;
1377 }
1378
1379 // FIXME: What about block pointers?
1380 // FIXME: What about Objective-C message sends?
1381}
1382
1383/// \brief Find the associated classes and namespaces for
1384/// argument-dependent lookup for a call with the given set of
1385/// arguments.
1386///
1387/// This routine computes the sets of associated classes and associated
Mike Stump1eb44332009-09-09 15:08:12 +00001388/// namespaces searched by argument-dependent lookup
Douglas Gregorfa047642009-02-04 00:32:51 +00001389/// (C++ [basic.lookup.argdep]) for a given set of arguments.
Mike Stump1eb44332009-09-09 15:08:12 +00001390void
Douglas Gregorfa047642009-02-04 00:32:51 +00001391Sema::FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1392 AssociatedNamespaceSet &AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001393 AssociatedClassSet &AssociatedClasses) {
Douglas Gregorfa047642009-02-04 00:32:51 +00001394 AssociatedNamespaces.clear();
1395 AssociatedClasses.clear();
1396
1397 // C++ [basic.lookup.koenig]p2:
1398 // For each argument type T in the function call, there is a set
1399 // of zero or more associated namespaces and a set of zero or more
1400 // associated classes to be considered. The sets of namespaces and
1401 // classes is determined entirely by the types of the function
1402 // arguments (and the namespace of any template template
Mike Stump1eb44332009-09-09 15:08:12 +00001403 // argument).
Douglas Gregorfa047642009-02-04 00:32:51 +00001404 for (unsigned ArgIdx = 0; ArgIdx != NumArgs; ++ArgIdx) {
1405 Expr *Arg = Args[ArgIdx];
1406
1407 if (Arg->getType() != Context.OverloadTy) {
1408 addAssociatedClassesAndNamespaces(Arg->getType(), Context,
John McCall6ff07852009-08-07 22:18:02 +00001409 AssociatedNamespaces,
1410 AssociatedClasses);
Douglas Gregorfa047642009-02-04 00:32:51 +00001411 continue;
1412 }
1413
1414 // [...] In addition, if the argument is the name or address of a
1415 // set of overloaded functions and/or function templates, its
1416 // associated classes and namespaces are the union of those
1417 // associated with each of the members of the set: the namespace
1418 // in which the function or function template is defined and the
1419 // classes and namespaces associated with its (non-dependent)
1420 // parameter types and return type.
1421 DeclRefExpr *DRE = 0;
Douglas Gregordaa439a2009-07-08 10:57:20 +00001422 TemplateIdRefExpr *TIRE = 0;
1423 Arg = Arg->IgnoreParens();
Douglas Gregorfa047642009-02-04 00:32:51 +00001424 if (UnaryOperator *unaryOp = dyn_cast<UnaryOperator>(Arg)) {
Douglas Gregordaa439a2009-07-08 10:57:20 +00001425 if (unaryOp->getOpcode() == UnaryOperator::AddrOf) {
Douglas Gregorfa047642009-02-04 00:32:51 +00001426 DRE = dyn_cast<DeclRefExpr>(unaryOp->getSubExpr());
Douglas Gregordaa439a2009-07-08 10:57:20 +00001427 TIRE = dyn_cast<TemplateIdRefExpr>(unaryOp->getSubExpr());
1428 }
1429 } else {
Douglas Gregorfa047642009-02-04 00:32:51 +00001430 DRE = dyn_cast<DeclRefExpr>(Arg);
Douglas Gregordaa439a2009-07-08 10:57:20 +00001431 TIRE = dyn_cast<TemplateIdRefExpr>(Arg);
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregordaa439a2009-07-08 10:57:20 +00001434 OverloadedFunctionDecl *Ovl = 0;
1435 if (DRE)
1436 Ovl = dyn_cast<OverloadedFunctionDecl>(DRE->getDecl());
1437 else if (TIRE)
Douglas Gregord99cbe62009-07-29 18:26:50 +00001438 Ovl = TIRE->getTemplateName().getAsOverloadedFunctionDecl();
Douglas Gregorfa047642009-02-04 00:32:51 +00001439 if (!Ovl)
1440 continue;
1441
1442 for (OverloadedFunctionDecl::function_iterator Func = Ovl->function_begin(),
1443 FuncEnd = Ovl->function_end();
1444 Func != FuncEnd; ++Func) {
Douglas Gregore53060f2009-06-25 22:08:12 +00001445 FunctionDecl *FDecl = dyn_cast<FunctionDecl>(*Func);
1446 if (!FDecl)
1447 FDecl = cast<FunctionTemplateDecl>(*Func)->getTemplatedDecl();
Douglas Gregorfa047642009-02-04 00:32:51 +00001448
1449 // Add the namespace in which this function was defined. Note
1450 // that, if this is a member function, we do *not* consider the
1451 // enclosing namespace of its class.
1452 DeclContext *Ctx = FDecl->getDeclContext();
John McCall6ff07852009-08-07 22:18:02 +00001453 CollectNamespace(AssociatedNamespaces, Ctx);
Douglas Gregorfa047642009-02-04 00:32:51 +00001454
1455 // Add the classes and namespaces associated with the parameter
1456 // types and return type of this function.
1457 addAssociatedClassesAndNamespaces(FDecl->getType(), Context,
John McCall6ff07852009-08-07 22:18:02 +00001458 AssociatedNamespaces,
1459 AssociatedClasses);
Douglas Gregorfa047642009-02-04 00:32:51 +00001460 }
1461 }
1462}
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001463
1464/// IsAcceptableNonMemberOperatorCandidate - Determine whether Fn is
1465/// an acceptable non-member overloaded operator for a call whose
1466/// arguments have types T1 (and, if non-empty, T2). This routine
1467/// implements the check in C++ [over.match.oper]p3b2 concerning
1468/// enumeration types.
Mike Stump1eb44332009-09-09 15:08:12 +00001469static bool
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001470IsAcceptableNonMemberOperatorCandidate(FunctionDecl *Fn,
1471 QualType T1, QualType T2,
1472 ASTContext &Context) {
Douglas Gregorba498172009-03-13 21:01:28 +00001473 if (T1->isDependentType() || (!T2.isNull() && T2->isDependentType()))
1474 return true;
1475
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001476 if (T1->isRecordType() || (!T2.isNull() && T2->isRecordType()))
1477 return true;
1478
John McCall183700f2009-09-21 23:43:11 +00001479 const FunctionProtoType *Proto = Fn->getType()->getAs<FunctionProtoType>();
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001480 if (Proto->getNumArgs() < 1)
1481 return false;
1482
1483 if (T1->isEnumeralType()) {
1484 QualType ArgType = Proto->getArgType(0).getNonReferenceType();
1485 if (Context.getCanonicalType(T1).getUnqualifiedType()
1486 == Context.getCanonicalType(ArgType).getUnqualifiedType())
1487 return true;
1488 }
1489
1490 if (Proto->getNumArgs() < 2)
1491 return false;
1492
1493 if (!T2.isNull() && T2->isEnumeralType()) {
1494 QualType ArgType = Proto->getArgType(1).getNonReferenceType();
1495 if (Context.getCanonicalType(T2).getUnqualifiedType()
1496 == Context.getCanonicalType(ArgType).getUnqualifiedType())
1497 return true;
1498 }
1499
1500 return false;
1501}
1502
Douglas Gregor6e378de2009-04-23 23:18:26 +00001503/// \brief Find the protocol with the given name, if any.
1504ObjCProtocolDecl *Sema::LookupProtocol(IdentifierInfo *II) {
John McCallf36e02d2009-10-09 21:13:30 +00001505 Decl *D = LookupSingleName(TUScope, II, LookupObjCProtocolName);
Douglas Gregor6e378de2009-04-23 23:18:26 +00001506 return cast_or_null<ObjCProtocolDecl>(D);
1507}
1508
Douglas Gregor8fc463a2009-04-24 00:11:27 +00001509/// \brief Find the Objective-C category implementation with the given
1510/// name, if any.
1511ObjCCategoryImplDecl *Sema::LookupObjCCategoryImpl(IdentifierInfo *II) {
John McCallf36e02d2009-10-09 21:13:30 +00001512 Decl *D = LookupSingleName(TUScope, II, LookupObjCCategoryImplName);
Douglas Gregor8fc463a2009-04-24 00:11:27 +00001513 return cast_or_null<ObjCCategoryImplDecl>(D);
1514}
1515
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001516void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
Mike Stump1eb44332009-09-09 15:08:12 +00001517 QualType T1, QualType T2,
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001518 FunctionSet &Functions) {
1519 // C++ [over.match.oper]p3:
1520 // -- The set of non-member candidates is the result of the
1521 // unqualified lookup of operator@ in the context of the
1522 // expression according to the usual rules for name lookup in
1523 // unqualified function calls (3.4.2) except that all member
1524 // functions are ignored. However, if no operand has a class
1525 // type, only those non-member functions in the lookup set
Eli Friedman33a31382009-08-05 19:21:58 +00001526 // that have a first parameter of type T1 or "reference to
1527 // (possibly cv-qualified) T1", when T1 is an enumeration
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001528 // type, or (if there is a right operand) a second parameter
Eli Friedman33a31382009-08-05 19:21:58 +00001529 // of type T2 or "reference to (possibly cv-qualified) T2",
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001530 // when T2 is an enumeration type, are candidate functions.
1531 DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op);
John McCallf36e02d2009-10-09 21:13:30 +00001532 LookupResult Operators;
1533 LookupName(Operators, S, OpName, LookupOperatorName);
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001535 assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous");
1536
John McCallf36e02d2009-10-09 21:13:30 +00001537 if (Operators.empty())
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001538 return;
1539
1540 for (LookupResult::iterator Op = Operators.begin(), OpEnd = Operators.end();
1541 Op != OpEnd; ++Op) {
Douglas Gregor364e0212009-06-27 21:05:07 +00001542 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*Op)) {
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001543 if (IsAcceptableNonMemberOperatorCandidate(FD, T1, T2, Context))
1544 Functions.insert(FD); // FIXME: canonical FD
Mike Stump1eb44332009-09-09 15:08:12 +00001545 } else if (FunctionTemplateDecl *FunTmpl
Douglas Gregor364e0212009-06-27 21:05:07 +00001546 = dyn_cast<FunctionTemplateDecl>(*Op)) {
1547 // FIXME: friend operators?
Mike Stump1eb44332009-09-09 15:08:12 +00001548 // FIXME: do we need to check IsAcceptableNonMemberOperatorCandidate,
Douglas Gregor364e0212009-06-27 21:05:07 +00001549 // later?
1550 if (!FunTmpl->getDeclContext()->isRecord())
1551 Functions.insert(FunTmpl);
1552 }
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001553 }
1554}
1555
John McCall6ff07852009-08-07 22:18:02 +00001556static void CollectFunctionDecl(Sema::FunctionSet &Functions,
1557 Decl *D) {
1558 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1559 Functions.insert(Func);
1560 else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
1561 Functions.insert(FunTmpl);
1562}
1563
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001564void Sema::ArgumentDependentLookup(DeclarationName Name,
1565 Expr **Args, unsigned NumArgs,
1566 FunctionSet &Functions) {
1567 // Find all of the associated namespaces and classes based on the
1568 // arguments we have.
1569 AssociatedNamespaceSet AssociatedNamespaces;
1570 AssociatedClassSet AssociatedClasses;
Mike Stump1eb44332009-09-09 15:08:12 +00001571 FindAssociatedClassesAndNamespaces(Args, NumArgs,
John McCall6ff07852009-08-07 22:18:02 +00001572 AssociatedNamespaces,
1573 AssociatedClasses);
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001574
1575 // C++ [basic.lookup.argdep]p3:
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001576 // Let X be the lookup set produced by unqualified lookup (3.4.1)
1577 // and let Y be the lookup set produced by argument dependent
1578 // lookup (defined as follows). If X contains [...] then Y is
1579 // empty. Otherwise Y is the set of declarations found in the
1580 // namespaces associated with the argument types as described
1581 // below. The set of declarations found by the lookup of the name
1582 // is the union of X and Y.
1583 //
1584 // Here, we compute Y and add its members to the overloaded
1585 // candidate set.
1586 for (AssociatedNamespaceSet::iterator NS = AssociatedNamespaces.begin(),
Mike Stump1eb44332009-09-09 15:08:12 +00001587 NSEnd = AssociatedNamespaces.end();
1588 NS != NSEnd; ++NS) {
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001589 // When considering an associated namespace, the lookup is the
1590 // same as the lookup performed when the associated namespace is
1591 // used as a qualifier (3.4.3.2) except that:
1592 //
1593 // -- Any using-directives in the associated namespace are
1594 // ignored.
1595 //
John McCall6ff07852009-08-07 22:18:02 +00001596 // -- Any namespace-scope friend functions declared in
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001597 // associated classes are visible within their respective
1598 // namespaces even if they are not visible during an ordinary
1599 // lookup (11.4).
1600 DeclContext::lookup_iterator I, E;
John McCall3f9a8a62009-08-11 06:59:38 +00001601 for (llvm::tie(I, E) = (*NS)->lookup(Name); I != E; ++I) {
John McCall6ff07852009-08-07 22:18:02 +00001602 Decl *D = *I;
John McCall02cace72009-08-28 07:59:38 +00001603 // If the only declaration here is an ordinary friend, consider
1604 // it only if it was declared in an associated classes.
1605 if (D->getIdentifierNamespace() == Decl::IDNS_OrdinaryFriend) {
John McCall3f9a8a62009-08-11 06:59:38 +00001606 DeclContext *LexDC = D->getLexicalDeclContext();
1607 if (!AssociatedClasses.count(cast<CXXRecordDecl>(LexDC)))
1608 continue;
1609 }
Mike Stump1eb44332009-09-09 15:08:12 +00001610
John McCall6ff07852009-08-07 22:18:02 +00001611 CollectFunctionDecl(Functions, D);
Douglas Gregor44bc2d52009-06-23 20:14:09 +00001612 }
1613 }
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001614}