[cfe-commits] r97112 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp lib/Sema/Sema.h lib/Sema/SemaCXXScopeSpec.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/TreeTransform.h
Douglas Gregor
dgregor at apple.com
Wed Feb 24 20:46:05 PST 2010
Author: dgregor
Date: Wed Feb 24 22:46:04 2010
New Revision: 97112
URL: http://llvm.org/viewvc/llvm-project?rev=97112&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/TreeTransform.h
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Feb 24 22:46:04 2010
@@ -365,11 +365,6 @@
/// \param II the identifier that represents the scope that this
/// nested-name-specifier refers to, e.g., the "bar" in "foo::bar::".
///
- /// \param MayBePseudoDestructor Whether this nested-name-specifier
- /// may be part of a pseudo-destructor, meaning that we are in a
- /// member access expression (such as p->T::~T()) and a '~' follows
- /// the '::'.
- ///
/// \param ObjectType if this nested-name-specifier occurs as part of a
/// C++ member access expression such as "x->Base::f", the type of the base
/// object (e.g., *x in the example, if "x" were a pointer).
@@ -384,7 +379,6 @@
SourceLocation IdLoc,
SourceLocation CCLoc,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
TypeTy *ObjectType,
bool EnteringContext) {
return 0;
@@ -399,7 +393,6 @@
virtual bool IsInvalidUnlessNestedName(Scope *S,
const CXXScopeSpec &SS,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
TypeTy *ObjectType,
bool EnteringContext) {
return false;
@@ -417,8 +410,7 @@
const CXXScopeSpec &SS,
TypeTy *Type,
SourceRange TypeRange,
- SourceLocation CCLoc,
- bool MayBePseudoDestructor) {
+ SourceLocation CCLoc) {
return 0;
}
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Feb 24 22:46:04 2010
@@ -1004,7 +1004,7 @@
if (LHS.isInvalid())
break;
- ParseOptionalCXXScopeSpecifier(SS, ObjectType, false,
+ ParseOptionalCXXScopeSpecifier(SS, ObjectType, false,
&MayBePseudoDestructor);
}
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Feb 24 22:46:04 2010
@@ -212,8 +212,7 @@
Actions.ActOnCXXNestedNameSpecifier(CurScope, SS,
TypeToken.getAnnotationValue(),
TypeToken.getAnnotationRange(),
- CCLoc,
- false));
+ CCLoc));
else
SS.setScopeRep(0);
SS.setEndLoc(CCLoc);
@@ -240,15 +239,7 @@
// If we get foo:bar, this is almost certainly a typo for foo::bar. Recover
// and emit a fixit hint for it.
if (Next.is(tok::colon) && !ColonIsSacred) {
- if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde) &&
- !Actions.isNonTypeNestedNameSpecifier(CurScope, SS, Tok.getLocation(),
- II, ObjectType)) {
- *MayBePseudoDestructor = true;
- return HasScopeSpecifier;
- }
-
- if (Actions.IsInvalidUnlessNestedName(CurScope, SS, II,
- false, ObjectType,
+ if (Actions.IsInvalidUnlessNestedName(CurScope, SS, II, ObjectType,
EnteringContext) &&
// If the token after the colon isn't an identifier, it's still an
// error, but they probably meant something else strange so don't
@@ -287,8 +278,7 @@
SS.setScopeRep(
Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, II,
- false, ObjectType,
- EnteringContext));
+ ObjectType, EnteringContext));
SS.setEndLoc(CCLoc);
continue;
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Feb 24 22:46:04 2010
@@ -2225,8 +2225,7 @@
virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
SourceLocation CCLoc);
- bool isAcceptableNestedNameSpecifier(NamedDecl *SD,
- bool MayBePseudoDestructor = false);
+ bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
virtual bool isNonTypeNestedNameSpecifier(Scope *S, const CXXScopeSpec &SS,
@@ -2239,7 +2238,6 @@
SourceLocation IdLoc,
SourceLocation CCLoc,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
QualType ObjectType,
NamedDecl *ScopeLookupResult,
bool EnteringContext,
@@ -2250,14 +2248,12 @@
SourceLocation IdLoc,
SourceLocation CCLoc,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
TypeTy *ObjectType,
bool EnteringContext);
virtual bool IsInvalidUnlessNestedName(Scope *S,
const CXXScopeSpec &SS,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
TypeTy *ObjectType,
bool EnteringContext);
@@ -2273,8 +2269,7 @@
const CXXScopeSpec &SS,
TypeTy *Type,
SourceRange TypeRange,
- SourceLocation CCLoc,
- bool MayBePseudoDestructor);
+ SourceLocation CCLoc);
virtual bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Wed Feb 24 22:46:04 2010
@@ -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);
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Feb 24 22:46:04 2010
@@ -133,7 +133,7 @@
isDependent = LookupCtx && LookupCtx->isDependentContext();
}
- LookInScope = (LookupCtx == 0) && !isDependent;
+ LookInScope = false;
} else if (ObjectTypePtr) {
// C++ [basic.lookup.classref]p3:
// If the unqualified-id is ~type-name, the type-name is looked up
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Feb 24 22:46:04 2010
@@ -4925,7 +4925,6 @@
NestedNameSpecifier *NNS
= TransformNestedNameSpecifier(T->getQualifier(),
/*FIXME:*/SourceRange(getBaseLocation()),
- false,
ObjectType);
if (!NNS)
return QualType();
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Feb 24 22:46:04 2010
@@ -1486,7 +1486,7 @@
const MultiLevelTemplateArgumentList &TemplateArgs) {
TemplateInstantiator Instantiator(*this, TemplateArgs, Range.getBegin(),
DeclarationName());
- return Instantiator.TransformNestedNameSpecifier(NNS, Range, false);
+ return Instantiator.TransformNestedNameSpecifier(NNS, Range);
}
TemplateName
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=97112&r1=97111&r2=97112&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Feb 24 22:46:04 2010
@@ -265,7 +265,6 @@
/// alternate behavior.
NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
SourceRange Range,
- bool MayBePseudoDestructor,
QualType ObjectType = QualType(),
NamedDecl *FirstQualifierInScope = 0);
@@ -556,7 +555,6 @@
NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
SourceRange Range,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
QualType ObjectType,
NamedDecl *FirstQualifierInScope);
@@ -579,8 +577,7 @@
NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
SourceRange Range,
bool TemplateKW,
- QualType T,
- bool MayBePseudoDestructor);
+ QualType T);
/// \brief Build a new template name given a nested name specifier, a flag
/// indicating whether the "template" keyword was provided, and the template
@@ -1712,7 +1709,6 @@
NestedNameSpecifier *
TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
SourceRange Range,
- bool MayBePseudoDestructor,
QualType ObjectType,
NamedDecl *FirstQualifierInScope) {
if (!NNS)
@@ -1722,7 +1718,6 @@
NestedNameSpecifier *Prefix = NNS->getPrefix();
if (Prefix) {
Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
- false,
ObjectType,
FirstQualifierInScope);
if (!Prefix)
@@ -1744,7 +1739,6 @@
return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
*NNS->getAsIdentifier(),
- MayBePseudoDestructor,
ObjectType,
FirstQualifierInScope);
@@ -1780,8 +1774,7 @@
return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
- T,
- MayBePseudoDestructor);
+ T);
}
}
@@ -1833,7 +1826,6 @@
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
/*FIXME:*/SourceRange(getDerived().getBaseLocation()),
- false,
ObjectType);
if (!NNS)
return TemplateName();
@@ -1861,7 +1853,6 @@
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
/*FIXME:*/SourceRange(getDerived().getBaseLocation()),
- false,
ObjectType);
if (!NNS && DTN->getQualifier())
return TemplateName();
@@ -2921,7 +2912,6 @@
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(T->getQualifier(),
SourceRange(),
- false,
ObjectType);
if (!NNS)
return QualType();
@@ -2956,7 +2946,7 @@
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
- false, ObjectType);
+ ObjectType);
if (!NNS)
return QualType();
@@ -3592,8 +3582,7 @@
NestedNameSpecifier *Qualifier = 0;
if (E->getQualifier()) {
Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
- E->getQualifierRange(),
- false);
+ E->getQualifierRange());
if (!Qualifier)
return SemaRef.ExprError();
}
@@ -3802,8 +3791,7 @@
if (E->hasQualifier()) {
Qualifier
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
- E->getQualifierRange(),
- false);
+ E->getQualifierRange());
if (Qualifier == 0)
return SemaRef.ExprError();
}
@@ -4685,7 +4673,6 @@
NestedNameSpecifier *Qualifier
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
E->getQualifierRange(),
- true,
ObjectType);
if (E->getQualifier() && !Qualifier)
return SemaRef.ExprError();
@@ -4786,8 +4773,7 @@
NestedNameSpecifier *Qualifier = 0;
if (Old->getQualifier()) {
Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
- Old->getQualifierRange(),
- false);
+ Old->getQualifierRange());
if (!Qualifier)
return SemaRef.ExprError();
@@ -4843,8 +4829,7 @@
DependentScopeDeclRefExpr *E) {
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
- E->getQualifierRange(),
- false);
+ E->getQualifierRange());
if (!NNS)
return SemaRef.ExprError();
@@ -5093,11 +5078,8 @@
NestedNameSpecifier *Qualifier = 0;
if (E->getQualifier()) {
- bool MayBePseudoDestructor
- = E->getMember().getNameKind() == DeclarationName::CXXDestructorName;
Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
E->getQualifierRange(),
- MayBePseudoDestructor,
ObjectType,
FirstQualifierInScope);
if (!Qualifier)
@@ -5172,8 +5154,7 @@
if (Old->getQualifier()) {
Qualifier
= getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
- Old->getQualifierRange(),
- false);
+ Old->getQualifierRange());
if (Qualifier == 0)
return SemaRef.ExprError();
}
@@ -5598,7 +5579,6 @@
TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
SourceRange Range,
IdentifierInfo &II,
- bool MayBePseudoDestructor,
QualType ObjectType,
NamedDecl *FirstQualifierInScope) {
CXXScopeSpec SS;
@@ -5608,7 +5588,6 @@
return static_cast<NestedNameSpecifier *>(
SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Range.getEnd(), II,
- MayBePseudoDestructor,
ObjectType,
FirstQualifierInScope,
false, false));
@@ -5627,9 +5606,8 @@
TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
SourceRange Range,
bool TemplateKW,
- QualType T,
- bool MayBePseudoDestructor) {
- if (MayBePseudoDestructor || T->isDependentType() || T->isRecordType() ||
+ QualType T) {
+ if (T->isDependentType() || T->isRecordType() ||
(SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
More information about the cfe-commits
mailing list