SemaCXXScopeSpec.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. //===--- 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. #include "clang/Sema/SemaInternal.h"
  14. #include "TypeLocBuilder.h"
  15. #include "clang/AST/ASTContext.h"
  16. #include "clang/AST/DeclTemplate.h"
  17. #include "clang/AST/ExprCXX.h"
  18. #include "clang/AST/NestedNameSpecifier.h"
  19. #include "clang/Basic/PartialDiagnostic.h"
  20. #include "clang/Sema/DeclSpec.h"
  21. #include "clang/Sema/Lookup.h"
  22. #include "clang/Sema/Template.h"
  23. #include "llvm/ADT/STLExtras.h"
  24. #include "llvm/Support/raw_ostream.h"
  25. using namespace clang;
  26. /// \brief Find the current instantiation that associated with the given type.
  27. static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
  28. DeclContext *CurContext) {
  29. if (T.isNull())
  30. return nullptr;
  31. const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
  32. if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
  33. CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
  34. if (!Record->isDependentContext() ||
  35. Record->isCurrentInstantiation(CurContext))
  36. return Record;
  37. return nullptr;
  38. } else if (isa<InjectedClassNameType>(Ty))
  39. return cast<InjectedClassNameType>(Ty)->getDecl();
  40. else
  41. return nullptr;
  42. }
  43. /// \brief Compute the DeclContext that is associated with the given type.
  44. ///
  45. /// \param T the type for which we are attempting to find a DeclContext.
  46. ///
  47. /// \returns the declaration context represented by the type T,
  48. /// or NULL if the declaration context cannot be computed (e.g., because it is
  49. /// dependent and not the current instantiation).
  50. DeclContext *Sema::computeDeclContext(QualType T) {
  51. if (!T->isDependentType())
  52. if (const TagType *Tag = T->getAs<TagType>())
  53. return Tag->getDecl();
  54. return ::getCurrentInstantiationOf(T, CurContext);
  55. }
  56. /// \brief Compute the DeclContext that is associated with the given
  57. /// scope specifier.
  58. ///
  59. /// \param SS the C++ scope specifier as it appears in the source
  60. ///
  61. /// \param EnteringContext when true, we will be entering the context of
  62. /// this scope specifier, so we can retrieve the declaration context of a
  63. /// class template or class template partial specialization even if it is
  64. /// not the current instantiation.
  65. ///
  66. /// \returns the declaration context represented by the scope specifier @p SS,
  67. /// or NULL if the declaration context cannot be computed (e.g., because it is
  68. /// dependent and not the current instantiation).
  69. DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS,
  70. bool EnteringContext) {
  71. if (!SS.isSet() || SS.isInvalid())
  72. return nullptr;
  73. NestedNameSpecifier *NNS = SS.getScopeRep();
  74. if (NNS->isDependent()) {
  75. // If this nested-name-specifier refers to the current
  76. // instantiation, return its DeclContext.
  77. if (CXXRecordDecl *Record = getCurrentInstantiationOf(NNS))
  78. return Record;
  79. if (EnteringContext) {
  80. const Type *NNSType = NNS->getAsType();
  81. if (!NNSType) {
  82. return nullptr;
  83. }
  84. // Look through type alias templates, per C++0x [temp.dep.type]p1.
  85. NNSType = Context.getCanonicalType(NNSType);
  86. if (const TemplateSpecializationType *SpecType
  87. = NNSType->getAs<TemplateSpecializationType>()) {
  88. // We are entering the context of the nested name specifier, so try to
  89. // match the nested name specifier to either a primary class template
  90. // or a class template partial specialization.
  91. if (ClassTemplateDecl *ClassTemplate
  92. = dyn_cast_or_null<ClassTemplateDecl>(
  93. SpecType->getTemplateName().getAsTemplateDecl())) {
  94. QualType ContextType
  95. = Context.getCanonicalType(QualType(SpecType, 0));
  96. // If the type of the nested name specifier is the same as the
  97. // injected class name of the named class template, we're entering
  98. // into that class template definition.
  99. QualType Injected
  100. = ClassTemplate->getInjectedClassNameSpecialization();
  101. if (Context.hasSameType(Injected, ContextType))
  102. return ClassTemplate->getTemplatedDecl();
  103. // If the type of the nested name specifier is the same as the
  104. // type of one of the class template's class template partial
  105. // specializations, we're entering into the definition of that
  106. // class template partial specialization.
  107. if (ClassTemplatePartialSpecializationDecl *PartialSpec
  108. = ClassTemplate->findPartialSpecialization(ContextType))
  109. return PartialSpec;
  110. }
  111. } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) {
  112. // The nested name specifier refers to a member of a class template.
  113. return RecordT->getDecl();
  114. }
  115. }
  116. return nullptr;
  117. }
  118. switch (NNS->getKind()) {
  119. case NestedNameSpecifier::Identifier:
  120. llvm_unreachable("Dependent nested-name-specifier has no DeclContext");
  121. case NestedNameSpecifier::Namespace:
  122. return NNS->getAsNamespace();
  123. case NestedNameSpecifier::NamespaceAlias:
  124. return NNS->getAsNamespaceAlias()->getNamespace();
  125. case NestedNameSpecifier::TypeSpec:
  126. case NestedNameSpecifier::TypeSpecWithTemplate: {
  127. const TagType *Tag = NNS->getAsType()->getAs<TagType>();
  128. assert(Tag && "Non-tag type in nested-name-specifier");
  129. return Tag->getDecl();
  130. }
  131. case NestedNameSpecifier::Global:
  132. return Context.getTranslationUnitDecl();
  133. case NestedNameSpecifier::Super:
  134. return NNS->getAsRecordDecl();
  135. }
  136. llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
  137. }
  138. bool Sema::isDependentScopeSpecifier(const CXXScopeSpec &SS) {
  139. if (!SS.isSet() || SS.isInvalid())
  140. return false;
  141. return SS.getScopeRep()->isDependent();
  142. }
  143. /// \brief If the given nested name specifier refers to the current
  144. /// instantiation, return the declaration that corresponds to that
  145. /// current instantiation (C++0x [temp.dep.type]p1).
  146. ///
  147. /// \param NNS a dependent nested name specifier.
  148. CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) {
  149. assert(getLangOpts().CPlusPlus && "Only callable in C++");
  150. assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
  151. if (!NNS->getAsType())
  152. return nullptr;
  153. QualType T = QualType(NNS->getAsType(), 0);
  154. return ::getCurrentInstantiationOf(T, CurContext);
  155. }
  156. /// \brief Require that the context specified by SS be complete.
  157. ///
  158. /// If SS refers to a type, this routine checks whether the type is
  159. /// complete enough (or can be made complete enough) for name lookup
  160. /// into the DeclContext. A type that is not yet completed can be
  161. /// considered "complete enough" if it is a class/struct/union/enum
  162. /// that is currently being defined. Or, if we have a type that names
  163. /// a class template specialization that is not a complete type, we
  164. /// will attempt to instantiate that class template.
  165. bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS,
  166. DeclContext *DC) {
  167. assert(DC && "given null context");
  168. TagDecl *tag = dyn_cast<TagDecl>(DC);
  169. // If this is a dependent type, then we consider it complete.
  170. if (!tag || tag->isDependentContext())
  171. return false;
  172. // If we're currently defining this type, then lookup into the
  173. // type is okay: don't complain that it isn't complete yet.
  174. QualType type = Context.getTypeDeclType(tag);
  175. const TagType *tagType = type->getAs<TagType>();
  176. if (tagType && tagType->isBeingDefined())
  177. return false;
  178. SourceLocation loc = SS.getLastQualifierNameLoc();
  179. if (loc.isInvalid()) loc = SS.getRange().getBegin();
  180. // The type must be complete.
  181. if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
  182. SS.getRange())) {
  183. SS.SetInvalid(SS.getRange());
  184. return true;
  185. }
  186. // Fixed enum types are complete, but they aren't valid as scopes
  187. // until we see a definition, so awkwardly pull out this special
  188. // case.
  189. // FIXME: The definition might not be visible; complain if it is not.
  190. const EnumType *enumType = dyn_cast_or_null<EnumType>(tagType);
  191. if (!enumType || enumType->getDecl()->isCompleteDefinition())
  192. return false;
  193. // Try to instantiate the definition, if this is a specialization of an
  194. // enumeration temploid.
  195. EnumDecl *ED = enumType->getDecl();
  196. if (EnumDecl *Pattern = ED->getInstantiatedFromMemberEnum()) {
  197. MemberSpecializationInfo *MSI = ED->getMemberSpecializationInfo();
  198. if (MSI->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) {
  199. if (InstantiateEnum(loc, ED, Pattern, getTemplateInstantiationArgs(ED),
  200. TSK_ImplicitInstantiation)) {
  201. SS.SetInvalid(SS.getRange());
  202. return true;
  203. }
  204. return false;
  205. }
  206. }
  207. Diag(loc, diag::err_incomplete_nested_name_spec)
  208. << type << SS.getRange();
  209. SS.SetInvalid(SS.getRange());
  210. return true;
  211. }
  212. bool Sema::ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc,
  213. CXXScopeSpec &SS) {
  214. SS.MakeGlobal(Context, CCLoc);
  215. return false;
  216. }
  217. bool Sema::ActOnSuperScopeSpecifier(SourceLocation SuperLoc,
  218. SourceLocation ColonColonLoc,
  219. CXXScopeSpec &SS) {
  220. CXXRecordDecl *RD = nullptr;
  221. for (Scope *S = getCurScope(); S; S = S->getParent()) {
  222. if (S->isFunctionScope()) {
  223. if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity()))
  224. RD = MD->getParent();
  225. break;
  226. }
  227. if (S->isClassScope()) {
  228. RD = cast<CXXRecordDecl>(S->getEntity());
  229. break;
  230. }
  231. }
  232. if (!RD) {
  233. Diag(SuperLoc, diag::err_invalid_super_scope);
  234. return true;
  235. } else if (RD->isLambda()) {
  236. Diag(SuperLoc, diag::err_super_in_lambda_unsupported);
  237. return true;
  238. } else if (RD->getNumBases() == 0) {
  239. Diag(SuperLoc, diag::err_no_base_classes) << RD->getName();
  240. return true;
  241. }
  242. SS.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
  243. return false;
  244. }
  245. /// \brief Determines whether the given declaration is an valid acceptable
  246. /// result for name lookup of a nested-name-specifier.
  247. /// \param SD Declaration checked for nested-name-specifier.
  248. /// \param IsExtension If not null and the declaration is accepted as an
  249. /// extension, the pointed variable is assigned true.
  250. bool Sema::isAcceptableNestedNameSpecifier(const NamedDecl *SD,
  251. bool *IsExtension) {
  252. if (!SD)
  253. return false;
  254. // Namespace and namespace aliases are fine.
  255. if (isa<NamespaceDecl>(SD) || isa<NamespaceAliasDecl>(SD))
  256. return true;
  257. if (!isa<TypeDecl>(SD))
  258. return false;
  259. // Determine whether we have a class (or, in C++11, an enum) or
  260. // a typedef thereof. If so, build the nested-name-specifier.
  261. QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
  262. if (T->isDependentType())
  263. return true;
  264. if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
  265. if (TD->getUnderlyingType()->isRecordType())
  266. return true;
  267. if (TD->getUnderlyingType()->isEnumeralType()) {
  268. if (Context.getLangOpts().CPlusPlus11)
  269. return true;
  270. if (IsExtension)
  271. *IsExtension = true;
  272. }
  273. } else if (isa<RecordDecl>(SD)) {
  274. return true;
  275. } else if (isa<EnumDecl>(SD)) {
  276. if (Context.getLangOpts().CPlusPlus11)
  277. return true;
  278. if (IsExtension)
  279. *IsExtension = true;
  280. }
  281. return false;
  282. }
  283. /// \brief If the given nested-name-specifier begins with a bare identifier
  284. /// (e.g., Base::), perform name lookup for that identifier as a
  285. /// nested-name-specifier within the given scope, and return the result of that
  286. /// name lookup.
  287. NamedDecl *Sema::FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS) {
  288. if (!S || !NNS)
  289. return nullptr;
  290. while (NNS->getPrefix())
  291. NNS = NNS->getPrefix();
  292. if (NNS->getKind() != NestedNameSpecifier::Identifier)
  293. return nullptr;
  294. LookupResult Found(*this, NNS->getAsIdentifier(), SourceLocation(),
  295. LookupNestedNameSpecifierName);
  296. LookupName(Found, S);
  297. assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet");
  298. if (!Found.isSingleResult())
  299. return nullptr;
  300. NamedDecl *Result = Found.getFoundDecl();
  301. if (isAcceptableNestedNameSpecifier(Result))
  302. return Result;
  303. return nullptr;
  304. }
  305. bool Sema::isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
  306. SourceLocation IdLoc,
  307. IdentifierInfo &II,
  308. ParsedType ObjectTypePtr) {
  309. QualType ObjectType = GetTypeFromParser(ObjectTypePtr);
  310. LookupResult Found(*this, &II, IdLoc, LookupNestedNameSpecifierName);
  311. // Determine where to perform name lookup
  312. DeclContext *LookupCtx = nullptr;
  313. bool isDependent = false;
  314. if (!ObjectType.isNull()) {
  315. // This nested-name-specifier occurs in a member access expression, e.g.,
  316. // x->B::f, and we are looking into the type of the object.
  317. assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
  318. LookupCtx = computeDeclContext(ObjectType);
  319. isDependent = ObjectType->isDependentType();
  320. } else if (SS.isSet()) {
  321. // This nested-name-specifier occurs after another nested-name-specifier,
  322. // so long into the context associated with the prior nested-name-specifier.
  323. LookupCtx = computeDeclContext(SS, false);
  324. isDependent = isDependentScopeSpecifier(SS);
  325. Found.setContextRange(SS.getRange());
  326. }
  327. if (LookupCtx) {
  328. // Perform "qualified" name lookup into the declaration context we
  329. // computed, which is either the type of the base of a member access
  330. // expression or the declaration context associated with a prior
  331. // nested-name-specifier.
  332. // The declaration context must be complete.
  333. if (!LookupCtx->isDependentContext() &&
  334. RequireCompleteDeclContext(SS, LookupCtx))
  335. return false;
  336. LookupQualifiedName(Found, LookupCtx);
  337. } else if (isDependent) {
  338. return false;
  339. } else {
  340. LookupName(Found, S);
  341. }
  342. Found.suppressDiagnostics();
  343. if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
  344. return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND);
  345. return false;
  346. }
  347. namespace {
  348. // Callback to only accept typo corrections that can be a valid C++ member
  349. // intializer: either a non-static field member or a base class.
  350. class NestedNameSpecifierValidatorCCC : public CorrectionCandidateCallback {
  351. public:
  352. explicit NestedNameSpecifierValidatorCCC(Sema &SRef)
  353. : SRef(SRef) {}
  354. bool ValidateCandidate(const TypoCorrection &candidate) override {
  355. return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl());
  356. }
  357. private:
  358. Sema &SRef;
  359. };
  360. }
  361. /// \brief Build a new nested-name-specifier for "identifier::", as described
  362. /// by ActOnCXXNestedNameSpecifier.
  363. ///
  364. /// \param S Scope in which the nested-name-specifier occurs.
  365. /// \param Identifier Identifier in the sequence "identifier" "::".
  366. /// \param IdentifierLoc Location of the \p Identifier.
  367. /// \param CCLoc Location of "::" following Identifier.
  368. /// \param ObjectType Type of postfix expression if the nested-name-specifier
  369. /// occurs in construct like: <tt>ptr->nns::f</tt>.
  370. /// \param EnteringContext If true, enter the context specified by the
  371. /// nested-name-specifier.
  372. /// \param SS Optional nested name specifier preceding the identifier.
  373. /// \param ScopeLookupResult Provides the result of name lookup within the
  374. /// scope of the nested-name-specifier that was computed at template
  375. /// definition time.
  376. /// \param ErrorRecoveryLookup Specifies if the method is called to improve
  377. /// error recovery and what kind of recovery is performed.
  378. /// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':'
  379. /// are allowed. The bool value pointed by this parameter is set to
  380. /// 'true' if the identifier is treated as if it was followed by ':',
  381. /// not '::'.
  382. ///
  383. /// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
  384. /// that it contains an extra parameter \p ScopeLookupResult, which provides
  385. /// the result of name lookup within the scope of the nested-name-specifier
  386. /// that was computed at template definition time.
  387. ///
  388. /// If ErrorRecoveryLookup is true, then this call is used to improve error
  389. /// recovery. This means that it should not emit diagnostics, it should
  390. /// just return true on failure. It also means it should only return a valid
  391. /// scope if it *knows* that the result is correct. It should not return in a
  392. /// dependent context, for example. Nor will it extend \p SS with the scope
  393. /// specifier.
  394. bool Sema::BuildCXXNestedNameSpecifier(Scope *S,
  395. IdentifierInfo &Identifier,
  396. SourceLocation IdentifierLoc,
  397. SourceLocation CCLoc,
  398. QualType ObjectType,
  399. bool EnteringContext,
  400. CXXScopeSpec &SS,
  401. NamedDecl *ScopeLookupResult,
  402. bool ErrorRecoveryLookup,
  403. bool *IsCorrectedToColon) {
  404. LookupResult Found(*this, &Identifier, IdentifierLoc,
  405. LookupNestedNameSpecifierName);
  406. // Determine where to perform name lookup
  407. DeclContext *LookupCtx = nullptr;
  408. bool isDependent = false;
  409. if (IsCorrectedToColon)
  410. *IsCorrectedToColon = false;
  411. if (!ObjectType.isNull()) {
  412. // This nested-name-specifier occurs in a member access expression, e.g.,
  413. // x->B::f, and we are looking into the type of the object.
  414. assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
  415. LookupCtx = computeDeclContext(ObjectType);
  416. isDependent = ObjectType->isDependentType();
  417. } else if (SS.isSet()) {
  418. // This nested-name-specifier occurs after another nested-name-specifier,
  419. // so look into the context associated with the prior nested-name-specifier.
  420. LookupCtx = computeDeclContext(SS, EnteringContext);
  421. isDependent = isDependentScopeSpecifier(SS);
  422. Found.setContextRange(SS.getRange());
  423. }
  424. bool ObjectTypeSearchedInScope = false;
  425. if (LookupCtx) {
  426. // Perform "qualified" name lookup into the declaration context we
  427. // computed, which is either the type of the base of a member access
  428. // expression or the declaration context associated with a prior
  429. // nested-name-specifier.
  430. // The declaration context must be complete.
  431. if (!LookupCtx->isDependentContext() &&
  432. RequireCompleteDeclContext(SS, LookupCtx))
  433. return true;
  434. LookupQualifiedName(Found, LookupCtx);
  435. if (!ObjectType.isNull() && Found.empty()) {
  436. // C++ [basic.lookup.classref]p4:
  437. // If the id-expression in a class member access is a qualified-id of
  438. // the form
  439. //
  440. // class-name-or-namespace-name::...
  441. //
  442. // the class-name-or-namespace-name following the . or -> operator is
  443. // looked up both in the context of the entire postfix-expression and in
  444. // the scope of the class of the object expression. If the name is found
  445. // only in the scope of the class of the object expression, the name
  446. // shall refer to a class-name. If the name is found only in the
  447. // context of the entire postfix-expression, the name shall refer to a
  448. // class-name or namespace-name. [...]
  449. //
  450. // Qualified name lookup into a class will not find a namespace-name,
  451. // so we do not need to diagnose that case specifically. However,
  452. // this qualified name lookup may find nothing. In that case, perform
  453. // unqualified name lookup in the given scope (if available) or
  454. // reconstruct the result from when name lookup was performed at template
  455. // definition time.
  456. if (S)
  457. LookupName(Found, S);
  458. else if (ScopeLookupResult)
  459. Found.addDecl(ScopeLookupResult);
  460. ObjectTypeSearchedInScope = true;
  461. }
  462. } else if (!isDependent) {
  463. // Perform unqualified name lookup in the current scope.
  464. LookupName(Found, S);
  465. }
  466. // If we performed lookup into a dependent context and did not find anything,
  467. // that's fine: just build a dependent nested-name-specifier.
  468. if (Found.empty() && isDependent &&
  469. !(LookupCtx && LookupCtx->isRecord() &&
  470. (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
  471. !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
  472. // Don't speculate if we're just trying to improve error recovery.
  473. if (ErrorRecoveryLookup)
  474. return true;
  475. // We were not able to compute the declaration context for a dependent
  476. // base object type or prior nested-name-specifier, so this
  477. // nested-name-specifier refers to an unknown specialization. Just build
  478. // a dependent nested-name-specifier.
  479. SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
  480. return false;
  481. }
  482. // FIXME: Deal with ambiguities cleanly.
  483. if (Found.empty() && !ErrorRecoveryLookup) {
  484. // If identifier is not found as class-name-or-namespace-name, but is found
  485. // as other entity, don't look for typos.
  486. LookupResult R(*this, Found.getLookupNameInfo(), LookupOrdinaryName);
  487. if (LookupCtx)
  488. LookupQualifiedName(R, LookupCtx);
  489. else if (S && !isDependent)
  490. LookupName(R, S);
  491. if (!R.empty()) {
  492. // The identifier is found in ordinary lookup. If correction to colon is
  493. // allowed, suggest replacement to ':'.
  494. if (IsCorrectedToColon) {
  495. *IsCorrectedToColon = true;
  496. Diag(CCLoc, diag::err_nested_name_spec_is_not_class)
  497. << &Identifier << getLangOpts().CPlusPlus
  498. << FixItHint::CreateReplacement(CCLoc, ":");
  499. if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
  500. Diag(ND->getLocation(), diag::note_declared_at);
  501. return true;
  502. }
  503. // Replacement '::' -> ':' is not allowed, just issue respective error.
  504. Diag(R.getNameLoc(), diag::err_expected_class_or_namespace)
  505. << &Identifier << getLangOpts().CPlusPlus;
  506. if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
  507. Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier;
  508. return true;
  509. }
  510. }
  511. if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
  512. // We haven't found anything, and we're not recovering from a
  513. // different kind of error, so look for typos.
  514. DeclarationName Name = Found.getLookupName();
  515. Found.clear();
  516. if (TypoCorrection Corrected = CorrectTypo(
  517. Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS,
  518. llvm::make_unique<NestedNameSpecifierValidatorCCC>(*this),
  519. CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
  520. if (LookupCtx) {
  521. bool DroppedSpecifier =
  522. Corrected.WillReplaceSpecifier() &&
  523. Name.getAsString() == Corrected.getAsString(getLangOpts());
  524. if (DroppedSpecifier)
  525. SS.clear();
  526. diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
  527. << Name << LookupCtx << DroppedSpecifier
  528. << SS.getRange());
  529. } else
  530. diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
  531. << Name);
  532. if (NamedDecl *ND = Corrected.getCorrectionDecl())
  533. Found.addDecl(ND);
  534. Found.setLookupName(Corrected.getCorrection());
  535. } else {
  536. Found.setLookupName(&Identifier);
  537. }
  538. }
  539. NamedDecl *SD = Found.getAsSingle<NamedDecl>();
  540. bool IsExtension = false;
  541. bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
  542. if (!AcceptSpec && IsExtension) {
  543. AcceptSpec = true;
  544. // HLSL Change: Suppress c++11 extension warnings for nested name specifier in HLSL2017
  545. if (getLangOpts().HLSLVersion < 2017)
  546. Diag(IdentifierLoc, diag::ext_nested_name_spec_is_enum);
  547. }
  548. if (AcceptSpec) {
  549. if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
  550. !getLangOpts().CPlusPlus11) {
  551. // C++03 [basic.lookup.classref]p4:
  552. // [...] If the name is found in both contexts, the
  553. // class-name-or-namespace-name shall refer to the same entity.
  554. //
  555. // We already found the name in the scope of the object. Now, look
  556. // into the current scope (the scope of the postfix-expression) to
  557. // see if we can find the same name there. As above, if there is no
  558. // scope, reconstruct the result from the template instantiation itself.
  559. //
  560. // Note that C++11 does *not* perform this redundant lookup.
  561. NamedDecl *OuterDecl;
  562. if (S) {
  563. LookupResult FoundOuter(*this, &Identifier, IdentifierLoc,
  564. LookupNestedNameSpecifierName);
  565. LookupName(FoundOuter, S);
  566. OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
  567. } else
  568. OuterDecl = ScopeLookupResult;
  569. if (isAcceptableNestedNameSpecifier(OuterDecl) &&
  570. OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
  571. (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
  572. !Context.hasSameType(
  573. Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
  574. Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
  575. if (ErrorRecoveryLookup)
  576. return true;
  577. Diag(IdentifierLoc,
  578. diag::err_nested_name_member_ref_lookup_ambiguous)
  579. << &Identifier;
  580. Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
  581. << ObjectType;
  582. Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
  583. // Fall through so that we'll pick the name we found in the object
  584. // type, since that's probably what the user wanted anyway.
  585. }
  586. }
  587. if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
  588. MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
  589. // If we're just performing this lookup for error-recovery purposes,
  590. // don't extend the nested-name-specifier. Just return now.
  591. if (ErrorRecoveryLookup)
  592. return false;
  593. // The use of a nested name specifier may trigger deprecation warnings.
  594. DiagnoseUseOfDecl(SD, CCLoc);
  595. if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
  596. SS.Extend(Context, Namespace, IdentifierLoc, CCLoc);
  597. return false;
  598. }
  599. if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
  600. SS.Extend(Context, Alias, IdentifierLoc, CCLoc);
  601. return false;
  602. }
  603. QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
  604. TypeLocBuilder TLB;
  605. if (isa<InjectedClassNameType>(T)) {
  606. InjectedClassNameTypeLoc InjectedTL
  607. = TLB.push<InjectedClassNameTypeLoc>(T);
  608. InjectedTL.setNameLoc(IdentifierLoc);
  609. } else if (isa<RecordType>(T)) {
  610. RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T);
  611. RecordTL.setNameLoc(IdentifierLoc);
  612. } else if (isa<TypedefType>(T)) {
  613. TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T);
  614. TypedefTL.setNameLoc(IdentifierLoc);
  615. } else if (isa<EnumType>(T)) {
  616. EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T);
  617. EnumTL.setNameLoc(IdentifierLoc);
  618. } else if (isa<TemplateTypeParmType>(T)) {
  619. TemplateTypeParmTypeLoc TemplateTypeTL
  620. = TLB.push<TemplateTypeParmTypeLoc>(T);
  621. TemplateTypeTL.setNameLoc(IdentifierLoc);
  622. } else if (isa<UnresolvedUsingType>(T)) {
  623. UnresolvedUsingTypeLoc UnresolvedTL
  624. = TLB.push<UnresolvedUsingTypeLoc>(T);
  625. UnresolvedTL.setNameLoc(IdentifierLoc);
  626. } else if (isa<SubstTemplateTypeParmType>(T)) {
  627. SubstTemplateTypeParmTypeLoc TL
  628. = TLB.push<SubstTemplateTypeParmTypeLoc>(T);
  629. TL.setNameLoc(IdentifierLoc);
  630. } else if (isa<SubstTemplateTypeParmPackType>(T)) {
  631. SubstTemplateTypeParmPackTypeLoc TL
  632. = TLB.push<SubstTemplateTypeParmPackTypeLoc>(T);
  633. TL.setNameLoc(IdentifierLoc);
  634. } else {
  635. llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier");
  636. }
  637. if (T->isEnumeralType())
  638. Diag(IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
  639. SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T),
  640. CCLoc);
  641. return false;
  642. }
  643. // Otherwise, we have an error case. If we don't want diagnostics, just
  644. // return an error now.
  645. if (ErrorRecoveryLookup)
  646. return true;
  647. // If we didn't find anything during our lookup, try again with
  648. // ordinary name lookup, which can help us produce better error
  649. // messages.
  650. if (Found.empty()) {
  651. Found.clear(LookupOrdinaryName);
  652. LookupName(Found, S);
  653. }
  654. // In Microsoft mode, if we are within a templated function and we can't
  655. // resolve Identifier, then extend the SS with Identifier. This will have
  656. // the effect of resolving Identifier during template instantiation.
  657. // The goal is to be able to resolve a function call whose
  658. // nested-name-specifier is located inside a dependent base class.
  659. // Example:
  660. //
  661. // class C {
  662. // public:
  663. // static void foo2() { }
  664. // };
  665. // template <class T> class A { public: typedef C D; };
  666. //
  667. // template <class T> class B : public A<T> {
  668. // public:
  669. // void foo() { D::foo2(); }
  670. // };
  671. if (getLangOpts().MSVCCompat) {
  672. DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
  673. if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
  674. CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent());
  675. if (ContainingClass && ContainingClass->hasAnyDependentBases()) {
  676. Diag(IdentifierLoc, diag::ext_undeclared_unqual_id_with_dependent_base)
  677. << &Identifier << ContainingClass;
  678. SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
  679. return false;
  680. }
  681. }
  682. }
  683. if (!Found.empty()) {
  684. if (TypeDecl *TD = Found.getAsSingle<TypeDecl>())
  685. Diag(IdentifierLoc, diag::err_expected_class_or_namespace)
  686. << QualType(TD->getTypeForDecl(), 0) << getLangOpts().CPlusPlus;
  687. else {
  688. Diag(IdentifierLoc, diag::err_expected_class_or_namespace)
  689. << &Identifier << getLangOpts().CPlusPlus;
  690. if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
  691. Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier;
  692. }
  693. } else if (SS.isSet())
  694. Diag(IdentifierLoc, diag::err_no_member) << &Identifier << LookupCtx
  695. << SS.getRange();
  696. else
  697. Diag(IdentifierLoc, diag::err_undeclared_var_use) << &Identifier;
  698. return true;
  699. }
  700. bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
  701. IdentifierInfo &Identifier,
  702. SourceLocation IdentifierLoc,
  703. SourceLocation CCLoc,
  704. ParsedType ObjectType,
  705. bool EnteringContext,
  706. CXXScopeSpec &SS,
  707. bool ErrorRecoveryLookup,
  708. bool *IsCorrectedToColon) {
  709. if (SS.isInvalid())
  710. return true;
  711. return BuildCXXNestedNameSpecifier(S, Identifier, IdentifierLoc, CCLoc,
  712. GetTypeFromParser(ObjectType),
  713. EnteringContext, SS,
  714. /*ScopeLookupResult=*/nullptr, false,
  715. IsCorrectedToColon);
  716. }
  717. bool Sema::ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
  718. const DeclSpec &DS,
  719. SourceLocation ColonColonLoc) {
  720. if (SS.isInvalid() || DS.getTypeSpecType() == DeclSpec::TST_error)
  721. return true;
  722. assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
  723. QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc());
  724. if (!T->isDependentType() && !T->getAs<TagType>()) {
  725. Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
  726. << T << getLangOpts().CPlusPlus;
  727. return true;
  728. }
  729. TypeLocBuilder TLB;
  730. DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
  731. DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc());
  732. SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T),
  733. ColonColonLoc);
  734. return false;
  735. }
  736. /// IsInvalidUnlessNestedName - This method is used for error recovery
  737. /// purposes to determine whether the specified identifier is only valid as
  738. /// a nested name specifier, for example a namespace name. It is
  739. /// conservatively correct to always return false from this method.
  740. ///
  741. /// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier.
  742. bool Sema::IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
  743. IdentifierInfo &Identifier,
  744. SourceLocation IdentifierLoc,
  745. SourceLocation ColonLoc,
  746. ParsedType ObjectType,
  747. bool EnteringContext) {
  748. if (SS.isInvalid())
  749. return false;
  750. return !BuildCXXNestedNameSpecifier(S, Identifier, IdentifierLoc, ColonLoc,
  751. GetTypeFromParser(ObjectType),
  752. EnteringContext, SS,
  753. /*ScopeLookupResult=*/nullptr, true);
  754. }
  755. bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
  756. CXXScopeSpec &SS,
  757. SourceLocation TemplateKWLoc,
  758. TemplateTy Template,
  759. SourceLocation TemplateNameLoc,
  760. SourceLocation LAngleLoc,
  761. ASTTemplateArgsPtr TemplateArgsIn,
  762. SourceLocation RAngleLoc,
  763. SourceLocation CCLoc,
  764. bool EnteringContext) {
  765. if (SS.isInvalid())
  766. return true;
  767. // Translate the parser's template argument list in our AST format.
  768. TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
  769. translateTemplateArguments(TemplateArgsIn, TemplateArgs);
  770. DependentTemplateName *DTN = Template.get().getAsDependentTemplateName();
  771. if (DTN && DTN->isIdentifier()) {
  772. // Handle a dependent template specialization for which we cannot resolve
  773. // the template name.
  774. assert(DTN->getQualifier() == SS.getScopeRep());
  775. QualType T = Context.getDependentTemplateSpecializationType(ETK_None,
  776. DTN->getQualifier(),
  777. DTN->getIdentifier(),
  778. TemplateArgs);
  779. // Create source-location information for this type.
  780. TypeLocBuilder Builder;
  781. DependentTemplateSpecializationTypeLoc SpecTL
  782. = Builder.push<DependentTemplateSpecializationTypeLoc>(T);
  783. SpecTL.setElaboratedKeywordLoc(SourceLocation());
  784. SpecTL.setQualifierLoc(SS.getWithLocInContext(Context));
  785. SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
  786. SpecTL.setTemplateNameLoc(TemplateNameLoc);
  787. SpecTL.setLAngleLoc(LAngleLoc);
  788. SpecTL.setRAngleLoc(RAngleLoc);
  789. for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
  790. SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
  791. SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
  792. CCLoc);
  793. return false;
  794. }
  795. TemplateDecl *TD = Template.get().getAsTemplateDecl();
  796. if (Template.get().getAsOverloadedTemplate() || DTN ||
  797. isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
  798. SourceRange R(TemplateNameLoc, RAngleLoc);
  799. if (SS.getRange().isValid())
  800. R.setBegin(SS.getRange().getBegin());
  801. Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
  802. << (TD && isa<VarTemplateDecl>(TD)) << Template.get() << R;
  803. NoteAllFoundTemplates(Template.get());
  804. return true;
  805. }
  806. // We were able to resolve the template name to an actual template.
  807. // Build an appropriate nested-name-specifier.
  808. QualType T = CheckTemplateIdType(Template.get(), TemplateNameLoc,
  809. TemplateArgs);
  810. if (T.isNull())
  811. return true;
  812. // Alias template specializations can produce types which are not valid
  813. // nested name specifiers.
  814. if (!T->isDependentType() && !T->getAs<TagType>()) {
  815. Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
  816. NoteAllFoundTemplates(Template.get());
  817. return true;
  818. }
  819. // Provide source-location information for the template specialization type.
  820. TypeLocBuilder Builder;
  821. TemplateSpecializationTypeLoc SpecTL
  822. = Builder.push<TemplateSpecializationTypeLoc>(T);
  823. SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
  824. SpecTL.setTemplateNameLoc(TemplateNameLoc);
  825. SpecTL.setLAngleLoc(LAngleLoc);
  826. SpecTL.setRAngleLoc(RAngleLoc);
  827. for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
  828. SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
  829. SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
  830. CCLoc);
  831. return false;
  832. }
  833. namespace {
  834. /// \brief A structure that stores a nested-name-specifier annotation,
  835. /// including both the nested-name-specifier
  836. struct NestedNameSpecifierAnnotation {
  837. NestedNameSpecifier *NNS;
  838. };
  839. }
  840. void *Sema::SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS) {
  841. if (SS.isEmpty() || SS.isInvalid())
  842. return nullptr;
  843. void *Mem = Context.Allocate((sizeof(NestedNameSpecifierAnnotation) +
  844. SS.location_size()),
  845. llvm::alignOf<NestedNameSpecifierAnnotation>());
  846. NestedNameSpecifierAnnotation *Annotation
  847. = new (Mem) NestedNameSpecifierAnnotation;
  848. Annotation->NNS = SS.getScopeRep();
  849. memcpy(Annotation + 1, SS.location_data(), SS.location_size());
  850. return Annotation;
  851. }
  852. void Sema::RestoreNestedNameSpecifierAnnotation(void *AnnotationPtr,
  853. SourceRange AnnotationRange,
  854. CXXScopeSpec &SS) {
  855. if (!AnnotationPtr) {
  856. SS.SetInvalid(AnnotationRange);
  857. return;
  858. }
  859. NestedNameSpecifierAnnotation *Annotation
  860. = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
  861. SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
  862. }
  863. bool Sema::ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
  864. assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
  865. NestedNameSpecifier *Qualifier = SS.getScopeRep();
  866. // There are only two places a well-formed program may qualify a
  867. // declarator: first, when defining a namespace or class member
  868. // out-of-line, and second, when naming an explicitly-qualified
  869. // friend function. The latter case is governed by
  870. // C++03 [basic.lookup.unqual]p10:
  871. // In a friend declaration naming a member function, a name used
  872. // in the function declarator and not part of a template-argument
  873. // in a template-id is first looked up in the scope of the member
  874. // function's class. If it is not found, or if the name is part of
  875. // a template-argument in a template-id, the look up is as
  876. // described for unqualified names in the definition of the class
  877. // granting friendship.
  878. // i.e. we don't push a scope unless it's a class member.
  879. switch (Qualifier->getKind()) {
  880. case NestedNameSpecifier::Global:
  881. case NestedNameSpecifier::Namespace:
  882. case NestedNameSpecifier::NamespaceAlias:
  883. // These are always namespace scopes. We never want to enter a
  884. // namespace scope from anything but a file context.
  885. return CurContext->getRedeclContext()->isFileContext();
  886. case NestedNameSpecifier::Identifier:
  887. case NestedNameSpecifier::TypeSpec:
  888. case NestedNameSpecifier::TypeSpecWithTemplate:
  889. case NestedNameSpecifier::Super:
  890. // These are never namespace scopes.
  891. return true;
  892. }
  893. llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
  894. }
  895. /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
  896. /// scope or nested-name-specifier) is parsed, part of a declarator-id.
  897. /// After this method is called, according to [C++ 3.4.3p3], names should be
  898. /// looked up in the declarator-id's scope, until the declarator is parsed and
  899. /// ActOnCXXExitDeclaratorScope is called.
  900. /// The 'SS' should be a non-empty valid CXXScopeSpec.
  901. bool Sema::ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS) {
  902. assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
  903. if (SS.isInvalid()) return true;
  904. DeclContext *DC = computeDeclContext(SS, true);
  905. if (!DC) return true;
  906. // Before we enter a declarator's context, we need to make sure that
  907. // it is a complete declaration context.
  908. if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
  909. return true;
  910. EnterDeclaratorContext(S, DC);
  911. // Rebuild the nested name specifier for the new scope.
  912. if (DC->isDependentContext())
  913. RebuildNestedNameSpecifierInCurrentInstantiation(SS);
  914. return false;
  915. }
  916. /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
  917. /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
  918. /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
  919. /// Used to indicate that names should revert to being looked up in the
  920. /// defining scope.
  921. void Sema::ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
  922. assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
  923. if (SS.isInvalid())
  924. return;
  925. assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
  926. "exiting declarator scope we never really entered");
  927. ExitDeclaratorContext(S);
  928. }