blob: ab0e709a97e7044e5158d1d4e8a49c0242429c8f [file] [log] [blame]
Cedric Venet084381332009-02-14 20:20:19 +00001//===--- SemaCXXScopeSpec.cpp - Semantic Analysis for C++ scope specifiers-===//
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 C++ semantic analysis for scope specifiers.
11//
12//===----------------------------------------------------------------------===//
13
John McCall83024632010-08-25 22:03:47 +000014#include "clang/Sema/SemaInternal.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "TypeLocBuilder.h"
Cedric Venet084381332009-02-14 20:20:19 +000016#include "clang/AST/ASTContext.h"
Douglas Gregorc9f9b862009-05-11 19:58:34 +000017#include "clang/AST/DeclTemplate.h"
Douglas Gregord8061562009-08-06 03:17:00 +000018#include "clang/AST/ExprCXX.h"
Douglas Gregor52537682009-03-19 00:18:19 +000019#include "clang/AST/NestedNameSpecifier.h"
Anders Carlssond624e162009-08-26 23:45:07 +000020#include "clang/Basic/PartialDiagnostic.h"
John McCall8b0666c2010-08-20 18:27:03 +000021#include "clang/Sema/DeclSpec.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/Sema/Lookup.h"
23#include "clang/Sema/Template.h"
Cedric Venet084381332009-02-14 20:20:19 +000024#include "llvm/ADT/STLExtras.h"
Douglas Gregor168190d2009-07-22 00:28:09 +000025#include "llvm/Support/raw_ostream.h"
Cedric Venet084381332009-02-14 20:20:19 +000026using namespace clang;
27
Douglas Gregor41127182009-11-04 22:49:18 +000028/// \brief Find the current instantiation that associated with the given type.
Richard Smithd80b2d52012-11-22 00:24:47 +000029static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
Douglas Gregorbf2b26d2011-02-19 19:24:40 +000030 DeclContext *CurContext) {
Douglas Gregor41127182009-11-04 22:49:18 +000031 if (T.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +000032 return nullptr;
John McCall2408e322010-04-27 00:57:59 +000033
34 const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
Douglas Gregorbf2b26d2011-02-19 19:24:40 +000035 if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
36 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
Richard Smithd80b2d52012-11-22 00:24:47 +000037 if (!Record->isDependentContext() ||
38 Record->isCurrentInstantiation(CurContext))
Douglas Gregorbf2b26d2011-02-19 19:24:40 +000039 return Record;
40
Craig Topperc3ec1492014-05-26 06:22:03 +000041 return nullptr;
Douglas Gregorbf2b26d2011-02-19 19:24:40 +000042 } else if (isa<InjectedClassNameType>(Ty))
John McCall2408e322010-04-27 00:57:59 +000043 return cast<InjectedClassNameType>(Ty)->getDecl();
44 else
Craig Topperc3ec1492014-05-26 06:22:03 +000045 return nullptr;
Douglas Gregor41127182009-11-04 22:49:18 +000046}
47
Douglas Gregorb7bfe792009-09-02 22:59:36 +000048/// \brief Compute the DeclContext that is associated with the given type.
49///
50/// \param T the type for which we are attempting to find a DeclContext.
51///
Mike Stump11289f42009-09-09 15:08:12 +000052/// \returns the declaration context represented by the type T,
Douglas Gregorb7bfe792009-09-02 22:59:36 +000053/// or NULL if the declaration context cannot be computed (e.g., because it is
54/// dependent and not the current instantiation).
55DeclContext *Sema::computeDeclContext(QualType T) {
Douglas Gregorbf2b26d2011-02-19 19:24:40 +000056 if (!T->isDependentType())
57 if (const TagType *Tag = T->getAs<TagType>())
58 return Tag->getDecl();
Mike Stump11289f42009-09-09 15:08:12 +000059
Douglas Gregorbf2b26d2011-02-19 19:24:40 +000060 return ::getCurrentInstantiationOf(T, CurContext);
Douglas Gregorb7bfe792009-09-02 22:59:36 +000061}
62
Douglas Gregor52537682009-03-19 00:18:19 +000063/// \brief Compute the DeclContext that is associated with the given
64/// scope specifier.
Douglas Gregord8d297c2009-07-21 23:53:31 +000065///
66/// \param SS the C++ scope specifier as it appears in the source
67///
68/// \param EnteringContext when true, we will be entering the context of
69/// this scope specifier, so we can retrieve the declaration context of a
70/// class template or class template partial specialization even if it is
71/// not the current instantiation.
72///
73/// \returns the declaration context represented by the scope specifier @p SS,
74/// or NULL if the declaration context cannot be computed (e.g., because it is
75/// dependent and not the current instantiation).
76DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS,
77 bool EnteringContext) {
Douglas Gregor52537682009-03-19 00:18:19 +000078 if (!SS.isSet() || SS.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +000079 return nullptr;
Douglas Gregor6bfde492009-03-18 00:36:05 +000080
Richard Smith74bb2d22013-03-26 00:54:11 +000081 NestedNameSpecifier *NNS = SS.getScopeRep();
Douglas Gregorc9f9b862009-05-11 19:58:34 +000082 if (NNS->isDependent()) {
83 // If this nested-name-specifier refers to the current
84 // instantiation, return its DeclContext.
85 if (CXXRecordDecl *Record = getCurrentInstantiationOf(NNS))
86 return Record;
Mike Stump11289f42009-09-09 15:08:12 +000087
Douglas Gregord8d297c2009-07-21 23:53:31 +000088 if (EnteringContext) {
John McCalle78aac42010-03-10 03:28:59 +000089 const Type *NNSType = NNS->getAsType();
90 if (!NNSType) {
Craig Topperc3ec1492014-05-26 06:22:03 +000091 return nullptr;
Richard Smith3f1b5d02011-05-05 21:57:07 +000092 }
93
94 // Look through type alias templates, per C++0x [temp.dep.type]p1.
95 NNSType = Context.getCanonicalType(NNSType);
96 if (const TemplateSpecializationType *SpecType
97 = NNSType->getAs<TemplateSpecializationType>()) {
Douglas Gregore861bac2009-08-25 22:51:20 +000098 // We are entering the context of the nested name specifier, so try to
99 // match the nested name specifier to either a primary class template
100 // or a class template partial specialization.
Mike Stump11289f42009-09-09 15:08:12 +0000101 if (ClassTemplateDecl *ClassTemplate
Douglas Gregord8d297c2009-07-21 23:53:31 +0000102 = dyn_cast_or_null<ClassTemplateDecl>(
103 SpecType->getTemplateName().getAsTemplateDecl())) {
Douglas Gregor15301382009-07-30 17:40:51 +0000104 QualType ContextType
105 = Context.getCanonicalType(QualType(SpecType, 0));
106
Douglas Gregord8d297c2009-07-21 23:53:31 +0000107 // If the type of the nested name specifier is the same as the
108 // injected class name of the named class template, we're entering
109 // into that class template definition.
John McCalle78aac42010-03-10 03:28:59 +0000110 QualType Injected
Douglas Gregor9961ce92010-07-08 18:37:38 +0000111 = ClassTemplate->getInjectedClassNameSpecialization();
Douglas Gregor15301382009-07-30 17:40:51 +0000112 if (Context.hasSameType(Injected, ContextType))
Douglas Gregord8d297c2009-07-21 23:53:31 +0000113 return ClassTemplate->getTemplatedDecl();
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregor15301382009-07-30 17:40:51 +0000115 // If the type of the nested name specifier is the same as the
116 // type of one of the class template's class template partial
117 // specializations, we're entering into the definition of that
118 // class template partial specialization.
119 if (ClassTemplatePartialSpecializationDecl *PartialSpec
Richard Smith6739a102016-05-05 00:56:12 +0000120 = ClassTemplate->findPartialSpecialization(ContextType)) {
121 // A declaration of the partial specialization must be visible.
122 // We can always recover here, because this only happens when we're
123 // entering the context, and that can't happen in a SFINAE context.
124 assert(!isSFINAEContext() &&
125 "partial specialization scope specifier in SFINAE context?");
126 if (!hasVisibleDeclaration(PartialSpec))
127 diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
128 MissingImportKind::PartialSpecialization,
129 /*Recover*/true);
Douglas Gregor15301382009-07-30 17:40:51 +0000130 return PartialSpec;
Richard Smith6739a102016-05-05 00:56:12 +0000131 }
Douglas Gregord8d297c2009-07-21 23:53:31 +0000132 }
John McCalle78aac42010-03-10 03:28:59 +0000133 } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) {
Douglas Gregore861bac2009-08-25 22:51:20 +0000134 // The nested name specifier refers to a member of a class template.
135 return RecordT->getDecl();
Douglas Gregord8d297c2009-07-21 23:53:31 +0000136 }
137 }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Craig Topperc3ec1492014-05-26 06:22:03 +0000139 return nullptr;
Douglas Gregorc9f9b862009-05-11 19:58:34 +0000140 }
Douglas Gregorf21eb492009-03-26 23:50:42 +0000141
142 switch (NNS->getKind()) {
143 case NestedNameSpecifier::Identifier:
David Blaikie83d382b2011-09-23 05:06:16 +0000144 llvm_unreachable("Dependent nested-name-specifier has no DeclContext");
Douglas Gregorf21eb492009-03-26 23:50:42 +0000145
146 case NestedNameSpecifier::Namespace:
147 return NNS->getAsNamespace();
148
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000149 case NestedNameSpecifier::NamespaceAlias:
150 return NNS->getAsNamespaceAlias()->getNamespace();
151
Douglas Gregorf21eb492009-03-26 23:50:42 +0000152 case NestedNameSpecifier::TypeSpec:
153 case NestedNameSpecifier::TypeSpecWithTemplate: {
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000154 const TagType *Tag = NNS->getAsType()->getAs<TagType>();
155 assert(Tag && "Non-tag type in nested-name-specifier");
156 return Tag->getDecl();
David Blaikie8a40f702012-01-17 06:56:22 +0000157 }
Douglas Gregorf21eb492009-03-26 23:50:42 +0000158
159 case NestedNameSpecifier::Global:
160 return Context.getTranslationUnitDecl();
Nikola Smiljanic67860242014-09-26 00:28:20 +0000161
162 case NestedNameSpecifier::Super:
163 return NNS->getAsRecordDecl();
Douglas Gregorf21eb492009-03-26 23:50:42 +0000164 }
165
David Blaikie8a40f702012-01-17 06:56:22 +0000166 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
Douglas Gregor6bfde492009-03-18 00:36:05 +0000167}
168
Douglas Gregor90a1a652009-03-19 17:26:29 +0000169bool Sema::isDependentScopeSpecifier(const CXXScopeSpec &SS) {
170 if (!SS.isSet() || SS.isInvalid())
171 return false;
172
Richard Smith74bb2d22013-03-26 00:54:11 +0000173 return SS.getScopeRep()->isDependent();
Douglas Gregor90a1a652009-03-19 17:26:29 +0000174}
175
Douglas Gregorc9f9b862009-05-11 19:58:34 +0000176/// \brief If the given nested name specifier refers to the current
177/// instantiation, return the declaration that corresponds to that
178/// current instantiation (C++0x [temp.dep.type]p1).
179///
180/// \param NNS a dependent nested name specifier.
181CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) {
David Blaikiebbafb8a2012-03-11 07:00:24 +0000182 assert(getLangOpts().CPlusPlus && "Only callable in C++");
Douglas Gregorc9f9b862009-05-11 19:58:34 +0000183 assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
184
Douglas Gregord8d297c2009-07-21 23:53:31 +0000185 if (!NNS->getAsType())
Craig Topperc3ec1492014-05-26 06:22:03 +0000186 return nullptr;
Mike Stump11289f42009-09-09 15:08:12 +0000187
Douglas Gregorb9a955d2009-07-31 18:32:42 +0000188 QualType T = QualType(NNS->getAsType(), 0);
Douglas Gregorbf2b26d2011-02-19 19:24:40 +0000189 return ::getCurrentInstantiationOf(T, CurContext);
Douglas Gregorc9f9b862009-05-11 19:58:34 +0000190}
191
Douglas Gregor26897462009-03-11 16:48:53 +0000192/// \brief Require that the context specified by SS be complete.
193///
194/// If SS refers to a type, this routine checks whether the type is
195/// complete enough (or can be made complete enough) for name lookup
196/// into the DeclContext. A type that is not yet completed can be
197/// considered "complete enough" if it is a class/struct/union/enum
198/// that is currently being defined. Or, if we have a type that names
199/// a class template specialization that is not a complete type, we
200/// will attempt to instantiate that class template.
John McCall0b66eb32010-05-01 00:40:08 +0000201bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS,
202 DeclContext *DC) {
Craig Topperc3ec1492014-05-26 06:22:03 +0000203 assert(DC && "given null context");
Mike Stump11289f42009-09-09 15:08:12 +0000204
Richard Smith4b38ded2012-03-14 23:13:10 +0000205 TagDecl *tag = dyn_cast<TagDecl>(DC);
Douglas Gregor8a6d15d2010-02-05 04:39:02 +0000206
Richard Smith4b38ded2012-03-14 23:13:10 +0000207 // If this is a dependent type, then we consider it complete.
Richard Smith6739a102016-05-05 00:56:12 +0000208 // FIXME: This is wrong; we should require a (visible) definition to
209 // exist in this case too.
Richard Smith4b38ded2012-03-14 23:13:10 +0000210 if (!tag || tag->isDependentContext())
211 return false;
Douglas Gregor26897462009-03-11 16:48:53 +0000212
Richard Smith4b38ded2012-03-14 23:13:10 +0000213 // If we're currently defining this type, then lookup into the
214 // type is okay: don't complain that it isn't complete yet.
215 QualType type = Context.getTypeDeclType(tag);
216 const TagType *tagType = type->getAs<TagType>();
217 if (tagType && tagType->isBeingDefined())
218 return false;
John McCall21878762011-07-06 06:57:57 +0000219
Richard Smith4b38ded2012-03-14 23:13:10 +0000220 SourceLocation loc = SS.getLastQualifierNameLoc();
221 if (loc.isInvalid()) loc = SS.getRange().getBegin();
John McCall21878762011-07-06 06:57:57 +0000222
Richard Smith4b38ded2012-03-14 23:13:10 +0000223 // The type must be complete.
Douglas Gregor7bfb2d02012-05-04 16:32:21 +0000224 if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
225 SS.getRange())) {
Richard Smith4b38ded2012-03-14 23:13:10 +0000226 SS.SetInvalid(SS.getRange());
227 return true;
Douglas Gregor26897462009-03-11 16:48:53 +0000228 }
229
Richard Smith4b38ded2012-03-14 23:13:10 +0000230 // Fixed enum types are complete, but they aren't valid as scopes
231 // until we see a definition, so awkwardly pull out this special
232 // case.
233 const EnumType *enumType = dyn_cast_or_null<EnumType>(tagType);
Richard Smith6739a102016-05-05 00:56:12 +0000234 if (!enumType)
Richard Smith4b38ded2012-03-14 23:13:10 +0000235 return false;
Richard Smith6739a102016-05-05 00:56:12 +0000236 if (enumType->getDecl()->isCompleteDefinition()) {
237 // If we know about the definition but it is not visible, complain.
238 NamedDecl *SuggestedDef = nullptr;
239 if (!hasVisibleDefinition(enumType->getDecl(), &SuggestedDef,
240 /*OnlyNeedComplete*/false)) {
241 // If the user is going to see an error here, recover by making the
242 // definition visible.
243 bool TreatAsComplete = !isSFINAEContext();
244 diagnoseMissingImport(loc, SuggestedDef, MissingImportKind::Definition,
245 /*Recover*/TreatAsComplete);
246 return !TreatAsComplete;
247 }
248 return false;
249 }
Richard Smith4b38ded2012-03-14 23:13:10 +0000250
251 // Try to instantiate the definition, if this is a specialization of an
252 // enumeration temploid.
253 EnumDecl *ED = enumType->getDecl();
254 if (EnumDecl *Pattern = ED->getInstantiatedFromMemberEnum()) {
255 MemberSpecializationInfo *MSI = ED->getMemberSpecializationInfo();
Richard Smith7d137e32012-03-23 03:33:32 +0000256 if (MSI->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) {
257 if (InstantiateEnum(loc, ED, Pattern, getTemplateInstantiationArgs(ED),
258 TSK_ImplicitInstantiation)) {
259 SS.SetInvalid(SS.getRange());
260 return true;
261 }
262 return false;
263 }
Richard Smith4b38ded2012-03-14 23:13:10 +0000264 }
265
266 Diag(loc, diag::err_incomplete_nested_name_spec)
267 << type << SS.getRange();
268 SS.SetInvalid(SS.getRange());
269 return true;
Douglas Gregor26897462009-03-11 16:48:53 +0000270}
Cedric Venet084381332009-02-14 20:20:19 +0000271
Nikola Smiljanic67860242014-09-26 00:28:20 +0000272bool Sema::ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc,
Douglas Gregor90c99722011-02-24 00:17:56 +0000273 CXXScopeSpec &SS) {
274 SS.MakeGlobal(Context, CCLoc);
275 return false;
Cedric Venet084381332009-02-14 20:20:19 +0000276}
277
Nikola Smiljanic67860242014-09-26 00:28:20 +0000278bool Sema::ActOnSuperScopeSpecifier(SourceLocation SuperLoc,
279 SourceLocation ColonColonLoc,
280 CXXScopeSpec &SS) {
281 CXXRecordDecl *RD = nullptr;
282 for (Scope *S = getCurScope(); S; S = S->getParent()) {
283 if (S->isFunctionScope()) {
284 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity()))
285 RD = MD->getParent();
286 break;
287 }
288 if (S->isClassScope()) {
289 RD = cast<CXXRecordDecl>(S->getEntity());
290 break;
291 }
292 }
293
294 if (!RD) {
295 Diag(SuperLoc, diag::err_invalid_super_scope);
296 return true;
297 } else if (RD->isLambda()) {
298 Diag(SuperLoc, diag::err_super_in_lambda_unsupported);
299 return true;
300 } else if (RD->getNumBases() == 0) {
301 Diag(SuperLoc, diag::err_no_base_classes) << RD->getName();
302 return true;
303 }
304
305 SS.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
306 return false;
307}
308
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000309/// \brief Determines whether the given declaration is an valid acceptable
310/// result for name lookup of a nested-name-specifier.
Serge Pavlov25a8afa2015-01-18 20:04:35 +0000311/// \param SD Declaration checked for nested-name-specifier.
312/// \param IsExtension If not null and the declaration is accepted as an
313/// extension, the pointed variable is assigned true.
314bool Sema::isAcceptableNestedNameSpecifier(const NamedDecl *SD,
315 bool *IsExtension) {
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000316 if (!SD)
317 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000318
Richard Smithf2005d32015-12-29 23:34:32 +0000319 SD = SD->getUnderlyingDecl();
320
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000321 // Namespace and namespace aliases are fine.
Richard Smithf2005d32015-12-29 23:34:32 +0000322 if (isa<NamespaceDecl>(SD))
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000323 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000324
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000325 if (!isa<TypeDecl>(SD))
326 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000327
Richard Smithc8239732011-10-18 21:39:00 +0000328 // Determine whether we have a class (or, in C++11, an enum) or
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000329 // a typedef thereof. If so, build the nested-name-specifier.
330 QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
331 if (T->isDependentType())
332 return true;
Serge Pavlov25a8afa2015-01-18 20:04:35 +0000333 if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
334 if (TD->getUnderlyingType()->isRecordType())
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000335 return true;
Serge Pavlov25a8afa2015-01-18 20:04:35 +0000336 if (TD->getUnderlyingType()->isEnumeralType()) {
337 if (Context.getLangOpts().CPlusPlus11)
338 return true;
339 if (IsExtension)
340 *IsExtension = true;
341 }
342 } else if (isa<RecordDecl>(SD)) {
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000343 return true;
Serge Pavlov25a8afa2015-01-18 20:04:35 +0000344 } else if (isa<EnumDecl>(SD)) {
345 if (Context.getLangOpts().CPlusPlus11)
346 return true;
347 if (IsExtension)
348 *IsExtension = true;
349 }
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000350
351 return false;
352}
353
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000354/// \brief If the given nested-name-specifier begins with a bare identifier
Mike Stump11289f42009-09-09 15:08:12 +0000355/// (e.g., Base::), perform name lookup for that identifier as a
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000356/// nested-name-specifier within the given scope, and return the result of that
357/// name lookup.
358NamedDecl *Sema::FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS) {
359 if (!S || !NNS)
Craig Topperc3ec1492014-05-26 06:22:03 +0000360 return nullptr;
Mike Stump11289f42009-09-09 15:08:12 +0000361
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000362 while (NNS->getPrefix())
363 NNS = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000365 if (NNS->getKind() != NestedNameSpecifier::Identifier)
Craig Topperc3ec1492014-05-26 06:22:03 +0000366 return nullptr;
Mike Stump11289f42009-09-09 15:08:12 +0000367
John McCall27b18f82009-11-17 02:14:36 +0000368 LookupResult Found(*this, NNS->getAsIdentifier(), SourceLocation(),
369 LookupNestedNameSpecifierName);
370 LookupName(Found, S);
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000371 assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet");
372
John McCall67c00872009-12-02 08:25:40 +0000373 if (!Found.isSingleResult())
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 return nullptr;
John McCall67c00872009-12-02 08:25:40 +0000375
376 NamedDecl *Result = Found.getFoundDecl();
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000377 if (isAcceptableNestedNameSpecifier(Result))
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000378 return Result;
Mike Stump11289f42009-09-09 15:08:12 +0000379
Craig Topperc3ec1492014-05-26 06:22:03 +0000380 return nullptr;
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000381}
382
Jeffrey Yasskinc76498d2010-04-08 16:38:48 +0000383bool Sema::isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
Douglas Gregor0d5b0a12010-02-24 21:29:12 +0000384 SourceLocation IdLoc,
385 IdentifierInfo &II,
John McCallba7bf592010-08-24 05:47:05 +0000386 ParsedType ObjectTypePtr) {
Douglas Gregor0d5b0a12010-02-24 21:29:12 +0000387 QualType ObjectType = GetTypeFromParser(ObjectTypePtr);
388 LookupResult Found(*this, &II, IdLoc, LookupNestedNameSpecifierName);
389
390 // Determine where to perform name lookup
Craig Topperc3ec1492014-05-26 06:22:03 +0000391 DeclContext *LookupCtx = nullptr;
Douglas Gregor0d5b0a12010-02-24 21:29:12 +0000392 bool isDependent = false;
393 if (!ObjectType.isNull()) {
394 // This nested-name-specifier occurs in a member access expression, e.g.,
395 // x->B::f, and we are looking into the type of the object.
396 assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
397 LookupCtx = computeDeclContext(ObjectType);
398 isDependent = ObjectType->isDependentType();
399 } else if (SS.isSet()) {
400 // This nested-name-specifier occurs after another nested-name-specifier,
401 // so long into the context associated with the prior nested-name-specifier.
402 LookupCtx = computeDeclContext(SS, false);
403 isDependent = isDependentScopeSpecifier(SS);
404 Found.setContextRange(SS.getRange());
405 }
406
407 if (LookupCtx) {
408 // Perform "qualified" name lookup into the declaration context we
409 // computed, which is either the type of the base of a member access
410 // expression or the declaration context associated with a prior
411 // nested-name-specifier.
412
413 // The declaration context must be complete.
John McCall0b66eb32010-05-01 00:40:08 +0000414 if (!LookupCtx->isDependentContext() &&
415 RequireCompleteDeclContext(SS, LookupCtx))
Douglas Gregor0d5b0a12010-02-24 21:29:12 +0000416 return false;
417
418 LookupQualifiedName(Found, LookupCtx);
419 } else if (isDependent) {
420 return false;
421 } else {
422 LookupName(Found, S);
423 }
424 Found.suppressDiagnostics();
425
Richard Smithf2005d32015-12-29 23:34:32 +0000426 return Found.getAsSingle<NamespaceDecl>();
Douglas Gregor0d5b0a12010-02-24 21:29:12 +0000427}
428
Kaelyn Uhrainfb96ec72012-01-12 22:32:39 +0000429namespace {
430
431// Callback to only accept typo corrections that can be a valid C++ member
432// intializer: either a non-static field member or a base class.
433class NestedNameSpecifierValidatorCCC : public CorrectionCandidateCallback {
434 public:
435 explicit NestedNameSpecifierValidatorCCC(Sema &SRef)
436 : SRef(SRef) {}
437
Craig Toppere14c0f82014-03-12 04:55:44 +0000438 bool ValidateCandidate(const TypoCorrection &candidate) override {
Kaelyn Uhrainfb96ec72012-01-12 22:32:39 +0000439 return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl());
440 }
441
442 private:
443 Sema &SRef;
444};
445
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000446}
Kaelyn Uhrainfb96ec72012-01-12 22:32:39 +0000447
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000448/// \brief Build a new nested-name-specifier for "identifier::", as described
449/// by ActOnCXXNestedNameSpecifier.
450///
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000451/// \param S Scope in which the nested-name-specifier occurs.
452/// \param Identifier Identifier in the sequence "identifier" "::".
453/// \param IdentifierLoc Location of the \p Identifier.
454/// \param CCLoc Location of "::" following Identifier.
455/// \param ObjectType Type of postfix expression if the nested-name-specifier
456/// occurs in construct like: <tt>ptr->nns::f</tt>.
457/// \param EnteringContext If true, enter the context specified by the
458/// nested-name-specifier.
459/// \param SS Optional nested name specifier preceding the identifier.
460/// \param ScopeLookupResult Provides the result of name lookup within the
461/// scope of the nested-name-specifier that was computed at template
462/// definition time.
463/// \param ErrorRecoveryLookup Specifies if the method is called to improve
464/// error recovery and what kind of recovery is performed.
465/// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':'
466/// are allowed. The bool value pointed by this parameter is set to
467/// 'true' if the identifier is treated as if it was followed by ':',
468/// not '::'.
469///
470/// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000471/// that it contains an extra parameter \p ScopeLookupResult, which provides
472/// the result of name lookup within the scope of the nested-name-specifier
Douglas Gregorad183ac2009-12-30 16:01:52 +0000473/// that was computed at template definition time.
Chris Lattner1c428032009-12-07 01:36:53 +0000474///
475/// If ErrorRecoveryLookup is true, then this call is used to improve error
476/// recovery. This means that it should not emit diagnostics, it should
Douglas Gregor90c99722011-02-24 00:17:56 +0000477/// just return true on failure. It also means it should only return a valid
Chris Lattner1c428032009-12-07 01:36:53 +0000478/// scope if it *knows* that the result is correct. It should not return in a
Douglas Gregor90c99722011-02-24 00:17:56 +0000479/// dependent context, for example. Nor will it extend \p SS with the scope
480/// specifier.
481bool Sema::BuildCXXNestedNameSpecifier(Scope *S,
482 IdentifierInfo &Identifier,
483 SourceLocation IdentifierLoc,
484 SourceLocation CCLoc,
485 QualType ObjectType,
486 bool EnteringContext,
487 CXXScopeSpec &SS,
488 NamedDecl *ScopeLookupResult,
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000489 bool ErrorRecoveryLookup,
490 bool *IsCorrectedToColon) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000491 LookupResult Found(*this, &Identifier, IdentifierLoc,
492 LookupNestedNameSpecifierName);
John McCall27b18f82009-11-17 02:14:36 +0000493
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000494 // Determine where to perform name lookup
Craig Topperc3ec1492014-05-26 06:22:03 +0000495 DeclContext *LookupCtx = nullptr;
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000496 bool isDependent = false;
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000497 if (IsCorrectedToColon)
498 *IsCorrectedToColon = false;
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000499 if (!ObjectType.isNull()) {
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000500 // This nested-name-specifier occurs in a member access expression, e.g.,
501 // x->B::f, and we are looking into the type of the object.
502 assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000503 LookupCtx = computeDeclContext(ObjectType);
504 isDependent = ObjectType->isDependentType();
505 } else if (SS.isSet()) {
506 // This nested-name-specifier occurs after another nested-name-specifier,
Richard Smith3f1b5d02011-05-05 21:57:07 +0000507 // so look into the context associated with the prior nested-name-specifier.
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000508 LookupCtx = computeDeclContext(SS, EnteringContext);
509 isDependent = isDependentScopeSpecifier(SS);
John McCall27b18f82009-11-17 02:14:36 +0000510 Found.setContextRange(SS.getRange());
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000511 }
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000513 bool ObjectTypeSearchedInScope = false;
514 if (LookupCtx) {
Mike Stump11289f42009-09-09 15:08:12 +0000515 // Perform "qualified" name lookup into the declaration context we
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000516 // computed, which is either the type of the base of a member access
Mike Stump11289f42009-09-09 15:08:12 +0000517 // expression or the declaration context associated with a prior
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000518 // nested-name-specifier.
Mike Stump11289f42009-09-09 15:08:12 +0000519
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000520 // The declaration context must be complete.
John McCall0b66eb32010-05-01 00:40:08 +0000521 if (!LookupCtx->isDependentContext() &&
522 RequireCompleteDeclContext(SS, LookupCtx))
Douglas Gregor90c99722011-02-24 00:17:56 +0000523 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000524
John McCall27b18f82009-11-17 02:14:36 +0000525 LookupQualifiedName(Found, LookupCtx);
Mike Stump11289f42009-09-09 15:08:12 +0000526
John McCall27b18f82009-11-17 02:14:36 +0000527 if (!ObjectType.isNull() && Found.empty()) {
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000528 // C++ [basic.lookup.classref]p4:
529 // If the id-expression in a class member access is a qualified-id of
Mike Stump11289f42009-09-09 15:08:12 +0000530 // the form
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000531 //
532 // class-name-or-namespace-name::...
533 //
Mike Stump11289f42009-09-09 15:08:12 +0000534 // the class-name-or-namespace-name following the . or -> operator is
535 // looked up both in the context of the entire postfix-expression and in
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000536 // the scope of the class of the object expression. If the name is found
Mike Stump11289f42009-09-09 15:08:12 +0000537 // only in the scope of the class of the object expression, the name
538 // shall refer to a class-name. If the name is found only in the
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000539 // context of the entire postfix-expression, the name shall refer to a
540 // class-name or namespace-name. [...]
541 //
542 // Qualified name lookup into a class will not find a namespace-name,
Douglas Gregor9d07dfa2011-05-15 17:27:27 +0000543 // so we do not need to diagnose that case specifically. However,
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000544 // this qualified name lookup may find nothing. In that case, perform
Mike Stump11289f42009-09-09 15:08:12 +0000545 // unqualified name lookup in the given scope (if available) or
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000546 // reconstruct the result from when name lookup was performed at template
547 // definition time.
548 if (S)
John McCall27b18f82009-11-17 02:14:36 +0000549 LookupName(Found, S);
John McCall9f3059a2009-10-09 21:13:30 +0000550 else if (ScopeLookupResult)
551 Found.addDecl(ScopeLookupResult);
Mike Stump11289f42009-09-09 15:08:12 +0000552
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000553 ObjectTypeSearchedInScope = true;
554 }
Douglas Gregordf65c8ed2010-07-28 14:49:07 +0000555 } else if (!isDependent) {
556 // Perform unqualified name lookup in the current scope.
557 LookupName(Found, S);
558 }
559
Richard Smith4b213d72015-11-12 22:40:09 +0000560 if (Found.isAmbiguous())
561 return true;
562
Douglas Gregordf65c8ed2010-07-28 14:49:07 +0000563 // If we performed lookup into a dependent context and did not find anything,
564 // that's fine: just build a dependent nested-name-specifier.
565 if (Found.empty() && isDependent &&
566 !(LookupCtx && LookupCtx->isRecord() &&
567 (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
568 !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
Chris Lattner1c428032009-12-07 01:36:53 +0000569 // Don't speculate if we're just trying to improve error recovery.
570 if (ErrorRecoveryLookup)
Douglas Gregor90c99722011-02-24 00:17:56 +0000571 return true;
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000572
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000573 // We were not able to compute the declaration context for a dependent
Mike Stump11289f42009-09-09 15:08:12 +0000574 // base object type or prior nested-name-specifier, so this
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000575 // nested-name-specifier refers to an unknown specialization. Just build
576 // a dependent nested-name-specifier.
Douglas Gregor90c99722011-02-24 00:17:56 +0000577 SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
578 return false;
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000579 }
580
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000581 if (Found.empty() && !ErrorRecoveryLookup) {
582 // If identifier is not found as class-name-or-namespace-name, but is found
583 // as other entity, don't look for typos.
584 LookupResult R(*this, Found.getLookupNameInfo(), LookupOrdinaryName);
585 if (LookupCtx)
586 LookupQualifiedName(R, LookupCtx);
587 else if (S && !isDependent)
588 LookupName(R, S);
589 if (!R.empty()) {
Richard Smith4b213d72015-11-12 22:40:09 +0000590 // Don't diagnose problems with this speculative lookup.
591 R.suppressDiagnostics();
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000592 // The identifier is found in ordinary lookup. If correction to colon is
593 // allowed, suggest replacement to ':'.
594 if (IsCorrectedToColon) {
595 *IsCorrectedToColon = true;
596 Diag(CCLoc, diag::err_nested_name_spec_is_not_class)
597 << &Identifier << getLangOpts().CPlusPlus
598 << FixItHint::CreateReplacement(CCLoc, ":");
599 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
600 Diag(ND->getLocation(), diag::note_declared_at);
601 return true;
602 }
603 // Replacement '::' -> ':' is not allowed, just issue respective error.
604 Diag(R.getNameLoc(), diag::err_expected_class_or_namespace)
605 << &Identifier << getLangOpts().CPlusPlus;
606 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
Alp Toker2afa8782014-05-28 12:20:14 +0000607 Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier;
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000608 return true;
609 }
610 }
611
Alp Tokerbfa39342014-01-14 12:51:41 +0000612 if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
Douglas Gregor532e68f2009-12-31 08:26:35 +0000613 // We haven't found anything, and we're not recovering from a
614 // different kind of error, so look for typos.
615 DeclarationName Name = Found.getLookupName();
Douglas Gregorc2fa1692011-06-28 16:20:02 +0000616 Found.clear();
Kaelyn Takata89c881b2014-10-27 18:07:29 +0000617 if (TypoCorrection Corrected = CorrectTypo(
618 Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS,
619 llvm::make_unique<NestedNameSpecifierValidatorCCC>(*this),
620 CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
Richard Smithf9b15102013-08-17 00:46:16 +0000621 if (LookupCtx) {
622 bool DroppedSpecifier =
623 Corrected.WillReplaceSpecifier() &&
624 Name.getAsString() == Corrected.getAsString(getLangOpts());
Kaelyn Uhraina6c78fe2013-12-16 19:19:18 +0000625 if (DroppedSpecifier)
626 SS.clear();
Richard Smithf9b15102013-08-17 00:46:16 +0000627 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
628 << Name << LookupCtx << DroppedSpecifier
629 << SS.getRange());
630 } else
631 diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
632 << Name);
Kaelyn Uhrain10413a42013-07-02 23:47:44 +0000633
Reid Kleckner4ce625c2016-02-16 19:16:20 +0000634 if (Corrected.getCorrectionSpecifier())
635 SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
636 SourceRange(Found.getNameLoc()));
637
Richard Smithde6d6c42015-12-29 19:43:10 +0000638 if (NamedDecl *ND = Corrected.getFoundDecl())
Douglas Gregorc2fa1692011-06-28 16:20:02 +0000639 Found.addDecl(ND);
Douglas Gregorc2fa1692011-06-28 16:20:02 +0000640 Found.setLookupName(Corrected.getCorrection());
Douglas Gregorc048c522010-06-29 19:27:42 +0000641 } else {
Douglas Gregor90c99722011-02-24 00:17:56 +0000642 Found.setLookupName(&Identifier);
Douglas Gregorc048c522010-06-29 19:27:42 +0000643 }
Douglas Gregor532e68f2009-12-31 08:26:35 +0000644 }
645
Richard Smithf2005d32015-12-29 23:34:32 +0000646 NamedDecl *SD =
647 Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr;
Serge Pavlov25a8afa2015-01-18 20:04:35 +0000648 bool IsExtension = false;
649 bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
650 if (!AcceptSpec && IsExtension) {
651 AcceptSpec = true;
652 Diag(IdentifierLoc, diag::ext_nested_name_spec_is_enum);
653 }
654 if (AcceptSpec) {
Douglas Gregor1b02e4a2012-05-01 20:23:02 +0000655 if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
Richard Smith2bf7fdb2013-01-02 11:42:31 +0000656 !getLangOpts().CPlusPlus11) {
Douglas Gregor1b02e4a2012-05-01 20:23:02 +0000657 // C++03 [basic.lookup.classref]p4:
Mike Stump11289f42009-09-09 15:08:12 +0000658 // [...] If the name is found in both contexts, the
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000659 // class-name-or-namespace-name shall refer to the same entity.
660 //
661 // We already found the name in the scope of the object. Now, look
662 // into the current scope (the scope of the postfix-expression) to
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000663 // see if we can find the same name there. As above, if there is no
664 // scope, reconstruct the result from the template instantiation itself.
Douglas Gregor1b02e4a2012-05-01 20:23:02 +0000665 //
666 // Note that C++11 does *not* perform this redundant lookup.
John McCall9f3059a2009-10-09 21:13:30 +0000667 NamedDecl *OuterDecl;
668 if (S) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000669 LookupResult FoundOuter(*this, &Identifier, IdentifierLoc,
670 LookupNestedNameSpecifierName);
John McCall27b18f82009-11-17 02:14:36 +0000671 LookupName(FoundOuter, S);
John McCall67c00872009-12-02 08:25:40 +0000672 OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
John McCall9f3059a2009-10-09 21:13:30 +0000673 } else
674 OuterDecl = ScopeLookupResult;
Mike Stump11289f42009-09-09 15:08:12 +0000675
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000676 if (isAcceptableNestedNameSpecifier(OuterDecl) &&
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000677 OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
678 (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
679 !Context.hasSameType(
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000680 Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000681 Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000682 if (ErrorRecoveryLookup)
683 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregor90c99722011-02-24 00:17:56 +0000685 Diag(IdentifierLoc,
686 diag::err_nested_name_member_ref_lookup_ambiguous)
687 << &Identifier;
688 Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
689 << ObjectType;
690 Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
691
692 // Fall through so that we'll pick the name we found in the object
693 // type, since that's probably what the user wanted anyway.
694 }
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000695 }
Mike Stump11289f42009-09-09 15:08:12 +0000696
Nico Weber72889432014-09-06 01:25:55 +0000697 if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
698 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
699
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000700 // If we're just performing this lookup for error-recovery purposes,
Douglas Gregor90c99722011-02-24 00:17:56 +0000701 // don't extend the nested-name-specifier. Just return now.
702 if (ErrorRecoveryLookup)
703 return false;
Aaron Ballman43f40102014-11-14 22:34:56 +0000704
705 // The use of a nested name specifier may trigger deprecation warnings.
706 DiagnoseUseOfDecl(SD, CCLoc);
707
Douglas Gregor90c99722011-02-24 00:17:56 +0000708
709 if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
710 SS.Extend(Context, Namespace, IdentifierLoc, CCLoc);
711 return false;
712 }
Mike Stump11289f42009-09-09 15:08:12 +0000713
Douglas Gregor90c99722011-02-24 00:17:56 +0000714 if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000715 SS.Extend(Context, Alias, IdentifierLoc, CCLoc);
Douglas Gregor90c99722011-02-24 00:17:56 +0000716 return false;
717 }
Mike Stump11289f42009-09-09 15:08:12 +0000718
Richard Smithf2005d32015-12-29 23:34:32 +0000719 QualType T =
720 Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl()));
Douglas Gregor90c99722011-02-24 00:17:56 +0000721 TypeLocBuilder TLB;
722 if (isa<InjectedClassNameType>(T)) {
723 InjectedClassNameTypeLoc InjectedTL
724 = TLB.push<InjectedClassNameTypeLoc>(T);
725 InjectedTL.setNameLoc(IdentifierLoc);
Douglas Gregordfd4b742011-05-04 23:05:40 +0000726 } else if (isa<RecordType>(T)) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000727 RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T);
728 RecordTL.setNameLoc(IdentifierLoc);
Douglas Gregordfd4b742011-05-04 23:05:40 +0000729 } else if (isa<TypedefType>(T)) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000730 TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T);
731 TypedefTL.setNameLoc(IdentifierLoc);
Douglas Gregordfd4b742011-05-04 23:05:40 +0000732 } else if (isa<EnumType>(T)) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000733 EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T);
734 EnumTL.setNameLoc(IdentifierLoc);
Douglas Gregordfd4b742011-05-04 23:05:40 +0000735 } else if (isa<TemplateTypeParmType>(T)) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000736 TemplateTypeParmTypeLoc TemplateTypeTL
737 = TLB.push<TemplateTypeParmTypeLoc>(T);
738 TemplateTypeTL.setNameLoc(IdentifierLoc);
Douglas Gregordfd4b742011-05-04 23:05:40 +0000739 } else if (isa<UnresolvedUsingType>(T)) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000740 UnresolvedUsingTypeLoc UnresolvedTL
741 = TLB.push<UnresolvedUsingTypeLoc>(T);
742 UnresolvedTL.setNameLoc(IdentifierLoc);
Douglas Gregordfd4b742011-05-04 23:05:40 +0000743 } else if (isa<SubstTemplateTypeParmType>(T)) {
744 SubstTemplateTypeParmTypeLoc TL
745 = TLB.push<SubstTemplateTypeParmTypeLoc>(T);
746 TL.setNameLoc(IdentifierLoc);
747 } else if (isa<SubstTemplateTypeParmPackType>(T)) {
748 SubstTemplateTypeParmPackTypeLoc TL
749 = TLB.push<SubstTemplateTypeParmPackTypeLoc>(T);
750 TL.setNameLoc(IdentifierLoc);
751 } else {
752 llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier");
Douglas Gregor90c99722011-02-24 00:17:56 +0000753 }
754
Richard Smith91c7bbd2011-10-20 03:28:47 +0000755 if (T->isEnumeralType())
756 Diag(IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
757
Douglas Gregor90c99722011-02-24 00:17:56 +0000758 SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T),
759 CCLoc);
760 return false;
Douglas Gregorb7bfe792009-09-02 22:59:36 +0000761 }
Mike Stump11289f42009-09-09 15:08:12 +0000762
Chris Lattner1c428032009-12-07 01:36:53 +0000763 // Otherwise, we have an error case. If we don't want diagnostics, just
764 // return an error now.
765 if (ErrorRecoveryLookup)
Douglas Gregor90c99722011-02-24 00:17:56 +0000766 return true;
Chris Lattner1c428032009-12-07 01:36:53 +0000767
Cedric Venet084381332009-02-14 20:20:19 +0000768 // If we didn't find anything during our lookup, try again with
769 // ordinary name lookup, which can help us produce better error
770 // messages.
John McCall67c00872009-12-02 08:25:40 +0000771 if (Found.empty()) {
John McCall27b18f82009-11-17 02:14:36 +0000772 Found.clear(LookupOrdinaryName);
773 LookupName(Found, S);
John McCall9f3059a2009-10-09 21:13:30 +0000774 }
Mike Stump11289f42009-09-09 15:08:12 +0000775
Francois Pichetb23dc092011-07-27 01:05:24 +0000776 // In Microsoft mode, if we are within a templated function and we can't
777 // resolve Identifier, then extend the SS with Identifier. This will have
778 // the effect of resolving Identifier during template instantiation.
779 // The goal is to be able to resolve a function call whose
780 // nested-name-specifier is located inside a dependent base class.
781 // Example:
782 //
783 // class C {
784 // public:
785 // static void foo2() { }
786 // };
787 // template <class T> class A { public: typedef C D; };
788 //
789 // template <class T> class B : public A<T> {
790 // public:
791 // void foo() { D::foo2(); }
792 // };
Alp Tokerbfa39342014-01-14 12:51:41 +0000793 if (getLangOpts().MSVCCompat) {
Francois Pichetb23dc092011-07-27 01:05:24 +0000794 DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
795 if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
Reid Kleckner062be332014-08-14 23:34:52 +0000796 CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent());
797 if (ContainingClass && ContainingClass->hasAnyDependentBases()) {
798 Diag(IdentifierLoc, diag::ext_undeclared_unqual_id_with_dependent_base)
799 << &Identifier << ContainingClass;
800 SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
801 return false;
802 }
Francois Pichetb23dc092011-07-27 01:05:24 +0000803 }
804 }
805
David Blaikie6cab5962014-02-09 06:54:23 +0000806 if (!Found.empty()) {
807 if (TypeDecl *TD = Found.getAsSingle<TypeDecl>())
808 Diag(IdentifierLoc, diag::err_expected_class_or_namespace)
809 << QualType(TD->getTypeForDecl(), 0) << getLangOpts().CPlusPlus;
810 else {
811 Diag(IdentifierLoc, diag::err_expected_class_or_namespace)
812 << &Identifier << getLangOpts().CPlusPlus;
813 if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
Alp Toker2afa8782014-05-28 12:20:14 +0000814 Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier;
David Blaikie6cab5962014-02-09 06:54:23 +0000815 }
816 } else if (SS.isSet())
817 Diag(IdentifierLoc, diag::err_no_member) << &Identifier << LookupCtx
818 << SS.getRange();
Cedric Venet084381332009-02-14 20:20:19 +0000819 else
David Blaikie6cab5962014-02-09 06:54:23 +0000820 Diag(IdentifierLoc, diag::err_undeclared_var_use) << &Identifier;
Mike Stump11289f42009-09-09 15:08:12 +0000821
Douglas Gregor90c99722011-02-24 00:17:56 +0000822 return true;
Cedric Venet084381332009-02-14 20:20:19 +0000823}
824
Douglas Gregor90c99722011-02-24 00:17:56 +0000825bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
826 IdentifierInfo &Identifier,
827 SourceLocation IdentifierLoc,
828 SourceLocation CCLoc,
829 ParsedType ObjectType,
830 bool EnteringContext,
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000831 CXXScopeSpec &SS,
832 bool ErrorRecoveryLookup,
833 bool *IsCorrectedToColon) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000834 if (SS.isInvalid())
835 return true;
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000836
Douglas Gregor90c99722011-02-24 00:17:56 +0000837 return BuildCXXNestedNameSpecifier(S, Identifier, IdentifierLoc, CCLoc,
838 GetTypeFromParser(ObjectType),
839 EnteringContext, SS,
Craig Topperc3ec1492014-05-26 06:22:03 +0000840 /*ScopeLookupResult=*/nullptr, false,
Serge Pavlov6a7ffbe2014-04-13 16:52:03 +0000841 IsCorrectedToColon);
Chris Lattner1c428032009-12-07 01:36:53 +0000842}
843
David Blaikie15a430a2011-12-04 05:04:18 +0000844bool Sema::ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
845 const DeclSpec &DS,
846 SourceLocation ColonColonLoc) {
847 if (SS.isInvalid() || DS.getTypeSpecType() == DeclSpec::TST_error)
848 return true;
849
850 assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
851
852 QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc());
853 if (!T->isDependentType() && !T->getAs<TagType>()) {
David Blaikie6cab5962014-02-09 06:54:23 +0000854 Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
David Blaikiebbafb8a2012-03-11 07:00:24 +0000855 << T << getLangOpts().CPlusPlus;
David Blaikie15a430a2011-12-04 05:04:18 +0000856 return true;
857 }
858
859 TypeLocBuilder TLB;
860 DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
861 DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc());
862 SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T),
863 ColonColonLoc);
864 return false;
865}
866
Chris Lattner1c428032009-12-07 01:36:53 +0000867/// IsInvalidUnlessNestedName - This method is used for error recovery
868/// purposes to determine whether the specified identifier is only valid as
869/// a nested name specifier, for example a namespace name. It is
870/// conservatively correct to always return false from this method.
871///
872/// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier.
Jeffrey Yasskinc76498d2010-04-08 16:38:48 +0000873bool Sema::IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
Douglas Gregor90c99722011-02-24 00:17:56 +0000874 IdentifierInfo &Identifier,
875 SourceLocation IdentifierLoc,
876 SourceLocation ColonLoc,
877 ParsedType ObjectType,
Chris Lattner1c428032009-12-07 01:36:53 +0000878 bool EnteringContext) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000879 if (SS.isInvalid())
880 return false;
Craig Topperc3ec1492014-05-26 06:22:03 +0000881
Douglas Gregor90c99722011-02-24 00:17:56 +0000882 return !BuildCXXNestedNameSpecifier(S, Identifier, IdentifierLoc, ColonLoc,
883 GetTypeFromParser(ObjectType),
884 EnteringContext, SS,
Craig Topperc3ec1492014-05-26 06:22:03 +0000885 /*ScopeLookupResult=*/nullptr, true);
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000886}
887
Douglas Gregor90c99722011-02-24 00:17:56 +0000888bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000889 CXXScopeSpec &SS,
890 SourceLocation TemplateKWLoc,
Douglas Gregor6e068012011-02-28 00:04:36 +0000891 TemplateTy Template,
892 SourceLocation TemplateNameLoc,
893 SourceLocation LAngleLoc,
894 ASTTemplateArgsPtr TemplateArgsIn,
895 SourceLocation RAngleLoc,
Douglas Gregor90c99722011-02-24 00:17:56 +0000896 SourceLocation CCLoc,
Douglas Gregor6e068012011-02-28 00:04:36 +0000897 bool EnteringContext) {
Douglas Gregor90c99722011-02-24 00:17:56 +0000898 if (SS.isInvalid())
899 return true;
900
Douglas Gregor6e068012011-02-28 00:04:36 +0000901 // Translate the parser's template argument list in our AST format.
902 TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
903 translateTemplateArguments(TemplateArgsIn, TemplateArgs);
904
Richard Smith72bfbd82013-12-04 00:28:23 +0000905 DependentTemplateName *DTN = Template.get().getAsDependentTemplateName();
906 if (DTN && DTN->isIdentifier()) {
Douglas Gregor6e068012011-02-28 00:04:36 +0000907 // Handle a dependent template specialization for which we cannot resolve
908 // the template name.
Richard Smith74bb2d22013-03-26 00:54:11 +0000909 assert(DTN->getQualifier() == SS.getScopeRep());
Douglas Gregor6e068012011-02-28 00:04:36 +0000910 QualType T = Context.getDependentTemplateSpecializationType(ETK_None,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000911 DTN->getQualifier(),
912 DTN->getIdentifier(),
Douglas Gregor6e068012011-02-28 00:04:36 +0000913 TemplateArgs);
914
915 // Create source-location information for this type.
916 TypeLocBuilder Builder;
Abramo Bagnara48c05be2012-02-06 14:41:24 +0000917 DependentTemplateSpecializationTypeLoc SpecTL
Douglas Gregor6e068012011-02-28 00:04:36 +0000918 = Builder.push<DependentTemplateSpecializationTypeLoc>(T);
Abramo Bagnara48c05be2012-02-06 14:41:24 +0000919 SpecTL.setElaboratedKeywordLoc(SourceLocation());
920 SpecTL.setQualifierLoc(SS.getWithLocInContext(Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +0000921 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
Abramo Bagnara48c05be2012-02-06 14:41:24 +0000922 SpecTL.setTemplateNameLoc(TemplateNameLoc);
Douglas Gregor6e068012011-02-28 00:04:36 +0000923 SpecTL.setLAngleLoc(LAngleLoc);
924 SpecTL.setRAngleLoc(RAngleLoc);
Douglas Gregor6e068012011-02-28 00:04:36 +0000925 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
926 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
927
Abramo Bagnara7945c982012-01-27 09:46:47 +0000928 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
Douglas Gregor6e068012011-02-28 00:04:36 +0000929 CCLoc);
930 return false;
931 }
Richard Smith72bfbd82013-12-04 00:28:23 +0000932
Richard Smithf95fe9b2013-12-04 00:47:45 +0000933 TemplateDecl *TD = Template.get().getAsTemplateDecl();
Richard Smith72bfbd82013-12-04 00:28:23 +0000934 if (Template.get().getAsOverloadedTemplate() || DTN ||
Richard Smithf95fe9b2013-12-04 00:47:45 +0000935 isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
Douglas Gregor8b6070b2011-03-04 21:37:14 +0000936 SourceRange R(TemplateNameLoc, RAngleLoc);
937 if (SS.getRange().isValid())
938 R.setBegin(SS.getRange().getBegin());
Richard Smith72bfbd82013-12-04 00:28:23 +0000939
Douglas Gregor8b6070b2011-03-04 21:37:14 +0000940 Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
Richard Smithf95fe9b2013-12-04 00:47:45 +0000941 << (TD && isa<VarTemplateDecl>(TD)) << Template.get() << R;
Douglas Gregor8b6070b2011-03-04 21:37:14 +0000942 NoteAllFoundTemplates(Template.get());
943 return true;
944 }
Richard Smith72bfbd82013-12-04 00:28:23 +0000945
Douglas Gregor6e068012011-02-28 00:04:36 +0000946 // We were able to resolve the template name to an actual template.
947 // Build an appropriate nested-name-specifier.
948 QualType T = CheckTemplateIdType(Template.get(), TemplateNameLoc,
949 TemplateArgs);
Douglas Gregor90c99722011-02-24 00:17:56 +0000950 if (T.isNull())
951 return true;
952
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 // Alias template specializations can produce types which are not valid
954 // nested name specifiers.
955 if (!T->isDependentType() && !T->getAs<TagType>()) {
956 Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
957 NoteAllFoundTemplates(Template.get());
958 return true;
959 }
Douglas Gregor6e068012011-02-28 00:04:36 +0000960
Abramo Bagnara48c05be2012-02-06 14:41:24 +0000961 // Provide source-location information for the template specialization type.
Douglas Gregor6e068012011-02-28 00:04:36 +0000962 TypeLocBuilder Builder;
Abramo Bagnara48c05be2012-02-06 14:41:24 +0000963 TemplateSpecializationTypeLoc SpecTL
Douglas Gregor6e068012011-02-28 00:04:36 +0000964 = Builder.push<TemplateSpecializationTypeLoc>(T);
Abramo Bagnara48c05be2012-02-06 14:41:24 +0000965 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
966 SpecTL.setTemplateNameLoc(TemplateNameLoc);
Douglas Gregor6e068012011-02-28 00:04:36 +0000967 SpecTL.setLAngleLoc(LAngleLoc);
968 SpecTL.setRAngleLoc(RAngleLoc);
Douglas Gregor6e068012011-02-28 00:04:36 +0000969 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
970 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
971
972
Abramo Bagnara7945c982012-01-27 09:46:47 +0000973 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
Douglas Gregor6e068012011-02-28 00:04:36 +0000974 CCLoc);
Douglas Gregor90c99722011-02-24 00:17:56 +0000975 return false;
Douglas Gregor7f741122009-02-25 19:37:18 +0000976}
977
Douglas Gregor869ad452011-02-24 17:54:50 +0000978namespace {
979 /// \brief A structure that stores a nested-name-specifier annotation,
980 /// including both the nested-name-specifier
981 struct NestedNameSpecifierAnnotation {
982 NestedNameSpecifier *NNS;
983 };
984}
985
986void *Sema::SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS) {
987 if (SS.isEmpty() || SS.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +0000988 return nullptr;
989
Douglas Gregor869ad452011-02-24 17:54:50 +0000990 void *Mem = Context.Allocate((sizeof(NestedNameSpecifierAnnotation) +
991 SS.location_size()),
992 llvm::alignOf<NestedNameSpecifierAnnotation>());
993 NestedNameSpecifierAnnotation *Annotation
994 = new (Mem) NestedNameSpecifierAnnotation;
995 Annotation->NNS = SS.getScopeRep();
996 memcpy(Annotation + 1, SS.location_data(), SS.location_size());
997 return Annotation;
998}
999
1000void Sema::RestoreNestedNameSpecifierAnnotation(void *AnnotationPtr,
1001 SourceRange AnnotationRange,
1002 CXXScopeSpec &SS) {
1003 if (!AnnotationPtr) {
1004 SS.SetInvalid(AnnotationRange);
1005 return;
1006 }
1007
1008 NestedNameSpecifierAnnotation *Annotation
1009 = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
1010 SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
1011}
1012
John McCall2b058ef2009-12-11 20:04:54 +00001013bool Sema::ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
1014 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1015
Richard Smith74bb2d22013-03-26 00:54:11 +00001016 NestedNameSpecifier *Qualifier = SS.getScopeRep();
John McCall2b058ef2009-12-11 20:04:54 +00001017
1018 // There are only two places a well-formed program may qualify a
1019 // declarator: first, when defining a namespace or class member
1020 // out-of-line, and second, when naming an explicitly-qualified
1021 // friend function. The latter case is governed by
1022 // C++03 [basic.lookup.unqual]p10:
1023 // In a friend declaration naming a member function, a name used
1024 // in the function declarator and not part of a template-argument
1025 // in a template-id is first looked up in the scope of the member
1026 // function's class. If it is not found, or if the name is part of
1027 // a template-argument in a template-id, the look up is as
1028 // described for unqualified names in the definition of the class
1029 // granting friendship.
1030 // i.e. we don't push a scope unless it's a class member.
1031
1032 switch (Qualifier->getKind()) {
1033 case NestedNameSpecifier::Global:
1034 case NestedNameSpecifier::Namespace:
Douglas Gregor7b26ff92011-02-24 02:36:08 +00001035 case NestedNameSpecifier::NamespaceAlias:
John McCall2b058ef2009-12-11 20:04:54 +00001036 // These are always namespace scopes. We never want to enter a
1037 // namespace scope from anything but a file context.
Sebastian Redl50c68252010-08-31 00:36:30 +00001038 return CurContext->getRedeclContext()->isFileContext();
John McCall2b058ef2009-12-11 20:04:54 +00001039
1040 case NestedNameSpecifier::Identifier:
1041 case NestedNameSpecifier::TypeSpec:
1042 case NestedNameSpecifier::TypeSpecWithTemplate:
Nikola Smiljanic67860242014-09-26 00:28:20 +00001043 case NestedNameSpecifier::Super:
John McCall2b058ef2009-12-11 20:04:54 +00001044 // These are never namespace scopes.
1045 return true;
1046 }
1047
David Blaikie8a40f702012-01-17 06:56:22 +00001048 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
John McCall2b058ef2009-12-11 20:04:54 +00001049}
1050
Cedric Venet084381332009-02-14 20:20:19 +00001051/// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1052/// scope or nested-name-specifier) is parsed, part of a declarator-id.
1053/// After this method is called, according to [C++ 3.4.3p3], names should be
1054/// looked up in the declarator-id's scope, until the declarator is parsed and
1055/// ActOnCXXExitDeclaratorScope is called.
1056/// The 'SS' should be a non-empty valid CXXScopeSpec.
Jeffrey Yasskinc76498d2010-04-08 16:38:48 +00001057bool Sema::ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS) {
Cedric Venet084381332009-02-14 20:20:19 +00001058 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
John McCall6df5fef2009-12-19 10:49:29 +00001059
1060 if (SS.isInvalid()) return true;
1061
1062 DeclContext *DC = computeDeclContext(SS, true);
1063 if (!DC) return true;
1064
1065 // Before we enter a declarator's context, we need to make sure that
1066 // it is a complete declaration context.
John McCall0b66eb32010-05-01 00:40:08 +00001067 if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
John McCall6df5fef2009-12-19 10:49:29 +00001068 return true;
1069
1070 EnterDeclaratorContext(S, DC);
John McCall2408e322010-04-27 00:57:59 +00001071
1072 // Rebuild the nested name specifier for the new scope.
1073 if (DC->isDependentContext())
1074 RebuildNestedNameSpecifierInCurrentInstantiation(SS);
1075
Douglas Gregor5013a7e2009-09-24 23:39:01 +00001076 return false;
Cedric Venet084381332009-02-14 20:20:19 +00001077}
1078
1079/// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1080/// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1081/// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1082/// Used to indicate that names should revert to being looked up in the
1083/// defining scope.
1084void Sema::ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
1085 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
Douglas Gregor053f6912009-08-26 00:04:55 +00001086 if (SS.isInvalid())
1087 return;
John McCall6df5fef2009-12-19 10:49:29 +00001088 assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
1089 "exiting declarator scope we never really entered");
1090 ExitDeclaratorContext(S);
Cedric Venet084381332009-02-14 20:20:19 +00001091}