Typedef->setInvalidDecl();
if (TypedefDecl *Prev = D->getPreviousDeclaration()) {
- NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(Prev, TemplateArgs);
+ NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(D->getLocation(), Prev,
+ TemplateArgs);
Typedef->setPreviousDeclaration(cast<TypedefDecl>(InstPrev));
}
// Hack to make this work almost well pending a rewrite.
if (ND->getDeclContext()->isRecord()) {
if (!ND->getDeclContext()->isDependentContext()) {
- NewND = SemaRef.FindInstantiatedDecl(ND, TemplateArgs);
+ NewND = SemaRef.FindInstantiatedDecl(D->getLocation(), ND,
+ TemplateArgs);
} else {
// FIXME: Hack to avoid crashing when incorrectly trying to instantiate
// templated friend declarations. This doesn't produce a correct AST;
if (D->isInjectedClassName())
PrevDecl = cast<CXXRecordDecl>(Owner);
else if (D->getPreviousDeclaration()) {
- NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getPreviousDeclaration(),
+ NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(),
+ D->getPreviousDeclaration(),
TemplateArgs);
if (!Prev) return 0;
PrevDecl = cast<CXXRecordDecl>(Prev);
if (D->getDeclContext()->isFunctionOrMethod())
DC = Owner;
else
- DC = SemaRef.FindInstantiatedContext(D->getDeclContext(), TemplateArgs);
+ DC = SemaRef.FindInstantiatedContext(D->getLocation(), D->getDeclContext(),
+ TemplateArgs);
FunctionDecl *Function =
FunctionDecl::Create(SemaRef.Context, DC, D->getLocation(),
I != E; ++I) {
UsingShadowDecl *Shadow = *I;
NamedDecl *InstTarget =
- cast<NamedDecl>(SemaRef.FindInstantiatedDecl(Shadow->getTargetDecl(),
+ cast<NamedDecl>(SemaRef.FindInstantiatedDecl(Shadow->getLocation(),
+ Shadow->getTargetDecl(),
TemplateArgs));
if (CheckRedeclaration &&
// Is this an anonymous union?
if (FieldDecl *UnionInit = Init->getAnonUnionMember())
- Member = cast<FieldDecl>(FindInstantiatedDecl(UnionInit, TemplateArgs));
+ Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMemberLocation(),
+ UnionInit, TemplateArgs));
else
- Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMember(),
+ Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMemberLocation(),
+ Init->getMember(),
TemplateArgs));
NewInit = BuildMemberInitializer(Member, (Expr **)NewArgs.data(),
/// within the current instantiation.
///
/// \returns NULL if there was an error
-DeclContext *Sema::FindInstantiatedContext(DeclContext* DC,
+DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC,
const MultiLevelTemplateArgumentList &TemplateArgs) {
if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) {
- Decl* ID = FindInstantiatedDecl(D, TemplateArgs);
+ Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs);
return cast_or_null<DeclContext>(ID);
} else return DC;
}
/// X<T>::<Kind>::KnownValue) to its instantiation
/// (X<int>::<Kind>::KnownValue). InstantiateCurrentDeclRef() performs
/// this mapping from within the instantiation of X<int>.
-NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D,
+NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
const MultiLevelTemplateArgumentList &TemplateArgs) {
DeclContext *ParentDC = D->getDeclContext();
if (isa<ParmVarDecl>(D) || isa<NonTypeTemplateParmDecl>(D) ||
if (!ParentDC->isDependentContext())
return D;
- ParentDC = FindInstantiatedContext(ParentDC, TemplateArgs);
+ ParentDC = FindInstantiatedContext(Loc, ParentDC, TemplateArgs);
if (!ParentDC)
return 0;
// We performed some kind of instantiation in the parent context,
// so now we need to look into the instantiated parent context to
// find the instantiation of the declaration D.
+
+ // If our context is a class template specialization, we may need
+ // to instantiate it before performing lookup into that context.
+ if (ClassTemplateSpecializationDecl *Spec
+ = dyn_cast<ClassTemplateSpecializationDecl>(ParentDC)) {
+ if (!Spec->isDependentContext()) {
+ QualType T = Context.getTypeDeclType(Spec);
+ if (const TagType *Tag = T->getAs<TagType>())
+ if (!Tag->isBeingDefined() &&
+ RequireCompleteType(Loc, T, diag::err_incomplete_type))
+ return 0;
+ }
+ }
+
NamedDecl *Result = 0;
if (D->getDeclName()) {
DeclContext::lookup_result Found = ParentDC->lookup(D->getDeclName());
///
/// By default, acts as the identity function on declarations. Subclasses
/// may override this function to provide alternate behavior.
- Decl *TransformDecl(Decl *D) { return D; }
+ Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
/// \brief Transform the definition of the given declaration.
///
/// By default, invokes TransformDecl() to transform the declaration.
/// Subclasses may override this function to provide alternate behavior.
- Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
+ Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
+ return getDerived().TransformDecl(D);
+ }
/// \brief Transform the given declaration, which was the first part of a
/// nested-name-specifier in a member access expression.
/// By default, invokes TransformDecl() to transform the declaration.
/// Subclasses may override this function to provide alternate behavior.
NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
- return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
+ return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
}
/// \brief Transform the given nested-name-specifier.
case NestedNameSpecifier::Namespace: {
NamespaceDecl *NS
= cast_or_null<NamespaceDecl>(
- getDerived().TransformDecl(NNS->getAsNamespace()));
+ getDerived().TransformDecl(Range.getBegin(),
+ NNS->getAsNamespace()));
if (!getDerived().AlwaysRebuild() &&
Prefix == NNS->getPrefix() &&
NS == NNS->getAsNamespace())
TemplateName
TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
QualType ObjectType) {
+ SourceLocation Loc = getDerived().getBaseLocation();
+
if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
if (TemplateDecl *Template = QTN->getTemplateDecl()) {
TemplateDecl *TransTemplate
- = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
+ = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
if (!TransTemplate)
return TemplateName();
if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
TemplateDecl *TransTemplate
- = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
+ = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
if (!TransTemplate)
return TemplateName();
if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
Name = ND->getDeclName();
TemporaryBase Rebase(*this, Input.getLocation(), Name);
- Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
+ Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
if (!D) return true;
Expr *SourceExpr = Input.getSourceDeclExpression();
UnresolvedUsingTypeLoc TL,
QualType ObjectType) {
UnresolvedUsingType *T = TL.getTypePtr();
- Decl *D = getDerived().TransformDecl(T->getDecl());
+ Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
if (!D)
return QualType();
QualType ObjectType) {
TypedefType *T = TL.getTypePtr();
TypedefDecl *Typedef
- = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
+ = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
+ T->getDecl()));
if (!Typedef)
return QualType();
QualType ObjectType) {
RecordType *T = TL.getTypePtr();
RecordDecl *Record
- = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
+ = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
+ T->getDecl()));
if (!Record)
return QualType();
QualType ObjectType) {
EnumType *T = TL.getTypePtr();
EnumDecl *Enum
- = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
+ = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
+ T->getDecl()));
if (!Enum)
return QualType();
}
ValueDecl *ND
- = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
+ = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
+ E->getDecl()));
if (!ND)
return SemaRef.ExprError();
}
ValueDecl *Member
- = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
+ = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
+ E->getMemberDecl()));
if (!Member)
return SemaRef.ExprError();
Sema::OwningExprResult
TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
ParmVarDecl *Param
- = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
+ = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
+ E->getParam()));
if (!Param)
return SemaRef.ExprError();
CXXConstructorDecl *Constructor = 0;
if (E->getConstructor()) {
Constructor = cast_or_null<CXXConstructorDecl>(
- getDerived().TransformDecl(E->getConstructor()));
+ getDerived().TransformDecl(E->getLocStart(),
+ E->getConstructor()));
if (!Constructor)
return SemaRef.ExprError();
}
FunctionDecl *OperatorNew = 0;
if (E->getOperatorNew()) {
OperatorNew = cast_or_null<FunctionDecl>(
- getDerived().TransformDecl(E->getOperatorNew()));
+ getDerived().TransformDecl(E->getLocStart(),
+ E->getOperatorNew()));
if (!OperatorNew)
return SemaRef.ExprError();
}
FunctionDecl *OperatorDelete = 0;
if (E->getOperatorDelete()) {
OperatorDelete = cast_or_null<FunctionDecl>(
- getDerived().TransformDecl(E->getOperatorDelete()));
+ getDerived().TransformDecl(E->getLocStart(),
+ E->getOperatorDelete()));
if (!OperatorDelete)
return SemaRef.ExprError();
}
FunctionDecl *OperatorDelete = 0;
if (E->getOperatorDelete()) {
OperatorDelete = cast_or_null<FunctionDecl>(
- getDerived().TransformDecl(E->getOperatorDelete()));
+ getDerived().TransformDecl(E->getLocStart(),
+ E->getOperatorDelete()));
if (!OperatorDelete)
return SemaRef.ExprError();
}
// Transform all the decls.
for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
E = Old->decls_end(); I != E; ++I) {
- NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
+ NamedDecl *InstD = static_cast<NamedDecl*>(
+ getDerived().TransformDecl(Old->getNameLoc(),
+ *I));
if (!InstD) {
// Silently ignore these if a UsingShadowDecl instantiated to nothing.
// This can happen because of dependent hiding.
CXXConstructorDecl *Constructor
= cast_or_null<CXXConstructorDecl>(
- getDerived().TransformDecl(E->getConstructor()));
+ getDerived().TransformDecl(E->getLocStart(),
+ E->getConstructor()));
if (!Constructor)
return SemaRef.ExprError();
CXXConstructorDecl *Constructor
= cast_or_null<CXXConstructorDecl>(
- getDerived().TransformDecl(E->getConstructor()));
+ getDerived().TransformDecl(E->getLocStart(),
+ E->getConstructor()));
if (!Constructor)
return SemaRef.ExprError();
// Transform all the decls.
for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
E = Old->decls_end(); I != E; ++I) {
- NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
+ NamedDecl *InstD = static_cast<NamedDecl*>(
+ getDerived().TransformDecl(Old->getMemberLoc(),
+ *I));
if (!InstD) {
// Silently ignore these if a UsingShadowDecl instantiated to nothing.
// This can happen because of dependent hiding.
TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
ObjCProtocolDecl *Protocol
= cast_or_null<ObjCProtocolDecl>(
- getDerived().TransformDecl(E->getProtocol()));
+ getDerived().TransformDecl(E->getLocStart(),
+ E->getProtocol()));
if (!Protocol)
return SemaRef.ExprError();