Restore the invariant that a nested-name-specifier can only contain
class types, dependent types, and namespaces. I had previously
weakened this invariant while working on parsing pseudo-destructor
expressions, but recent work in that area has made these changes
unnecessary.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97112 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp
index 4f8a414..971b78c 100644
--- a/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/lib/Sema/SemaCXXScopeSpec.cpp
@@ -176,15 +176,16 @@
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate: {
- if (const TagType *Tag = NNS->getAsType()->getAs<TagType>())
- return Tag->getDecl();
- break;
- }
+ const TagType *Tag = NNS->getAsType()->getAs<TagType>();
+ assert(Tag && "Non-tag type in nested-name-specifier");
+ return Tag->getDecl();
+ } break;
case NestedNameSpecifier::Global:
return Context.getTranslationUnitDecl();
}
+ // Required to silence a GCC warning.
return 0;
}
@@ -269,8 +270,7 @@
/// \brief Determines whether the given declaration is an valid acceptable
/// result for name lookup of a nested-name-specifier.
-bool Sema::isAcceptableNestedNameSpecifier(NamedDecl *SD,
- bool MayBePseudoDestructor) {
+bool Sema::isAcceptableNestedNameSpecifier(NamedDecl *SD) {
if (!SD)
return false;
@@ -281,11 +281,6 @@
if (!isa<TypeDecl>(SD))
return false;
- // If this may be part of a pseudo-destructor expression, we'll
- // accept any type.
- if (MayBePseudoDestructor)
- return true;
-
// Determine whether we have a class (or, in C++0x, an enum) or
// a typedef thereof. If so, build the nested-name-specifier.
QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
@@ -326,7 +321,7 @@
return 0;
NamedDecl *Result = Found.getFoundDecl();
- if (isAcceptableNestedNameSpecifier(Result, true))
+ if (isAcceptableNestedNameSpecifier(Result))
return Result;
return 0;
@@ -398,7 +393,6 @@
SourceLocation IdLoc,
SourceLocation CCLoc,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
QualType ObjectType,
NamedDecl *ScopeLookupResult,
bool EnteringContext,
@@ -493,8 +487,7 @@
DeclarationName Name = Found.getLookupName();
if (CorrectTypo(Found, S, &SS, LookupCtx, EnteringContext) &&
Found.isSingleResult() &&
- isAcceptableNestedNameSpecifier(Found.getAsSingle<NamedDecl>(),
- MayBePseudoDestructor)) {
+ isAcceptableNestedNameSpecifier(Found.getAsSingle<NamedDecl>())) {
if (LookupCtx)
Diag(Found.getNameLoc(), diag::err_no_member_suggest)
<< Name << LookupCtx << Found.getLookupName() << SS.getRange()
@@ -514,7 +507,7 @@
}
NamedDecl *SD = Found.getAsSingle<NamedDecl>();
- if (isAcceptableNestedNameSpecifier(SD, MayBePseudoDestructor)) {
+ if (isAcceptableNestedNameSpecifier(SD)) {
if (!ObjectType.isNull() && !ObjectTypeSearchedInScope) {
// C++ [basic.lookup.classref]p4:
// [...] If the name is found in both contexts, the
@@ -526,14 +519,13 @@
// scope, reconstruct the result from the template instantiation itself.
NamedDecl *OuterDecl;
if (S) {
- LookupResult FoundOuter(*this, &II, IdLoc,
- LookupNestedNameSpecifierName);
+ LookupResult FoundOuter(*this, &II, IdLoc, LookupNestedNameSpecifierName);
LookupName(FoundOuter, S);
OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
} else
OuterDecl = ScopeLookupResult;
- if (isAcceptableNestedNameSpecifier(OuterDecl, MayBePseudoDestructor) &&
+ if (isAcceptableNestedNameSpecifier(OuterDecl) &&
OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
(!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
!Context.hasSameType(
@@ -610,11 +602,9 @@
SourceLocation IdLoc,
SourceLocation CCLoc,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
TypeTy *ObjectTypePtr,
bool EnteringContext) {
return BuildCXXNestedNameSpecifier(S, SS, IdLoc, CCLoc, II,
- MayBePseudoDestructor,
QualType::getFromOpaquePtr(ObjectTypePtr),
/*ScopeLookupResult=*/0, EnteringContext,
false);
@@ -627,13 +617,10 @@
///
/// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier.
bool Sema::IsInvalidUnlessNestedName(Scope *S, const CXXScopeSpec &SS,
- IdentifierInfo &II,
- bool MayBePseudoDestructor,
- TypeTy *ObjectType,
+ IdentifierInfo &II, TypeTy *ObjectType,
bool EnteringContext) {
return BuildCXXNestedNameSpecifier(S, SS, SourceLocation(), SourceLocation(),
- II, MayBePseudoDestructor,
- QualType::getFromOpaquePtr(ObjectType),
+ II, QualType::getFromOpaquePtr(ObjectType),
/*ScopeLookupResult=*/0, EnteringContext,
true);
}
@@ -642,8 +629,7 @@
const CXXScopeSpec &SS,
TypeTy *Ty,
SourceRange TypeRange,
- SourceLocation CCLoc,
- bool MayBePseudoDestructor) {
+ SourceLocation CCLoc) {
NestedNameSpecifier *Prefix
= static_cast<NestedNameSpecifier *>(SS.getScopeRep());
QualType T = GetTypeFromParser(Ty);