diff options
author | John McCall <rjmccall@apple.com> | 2009-09-11 04:59:25 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-09-11 04:59:25 +0000 |
commit | c4e7019d5c9034a2d84ee4695f8e98dc025ac131 (patch) | |
tree | da8b19b3e6e6f62ddc50db7209b8dd0421fd15a8 /lib/Sema/SemaTemplateInstantiate.cpp | |
parent | 66847a2826c97b8e09aec304a0a7b4fe1dc35969 (diff) |
Support elaborated dependent types and diagnose tag mismatches.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81504 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 651d4a50dc..e719bbde92 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -391,6 +391,10 @@ namespace { IdentifierInfo *Name, SourceLocation Loc, SourceRange TypeRange); + /// \brief Check for tag mismatches when instantiating an + /// elaborated type. + QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag); + Sema::OwningExprResult TransformPredefinedExpr(PredefinedExpr *E); Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E); @@ -451,7 +455,33 @@ TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, return Var; } -Sema::OwningExprResult +QualType +TemplateInstantiator::RebuildElaboratedType(QualType T, + ElaboratedType::TagKind Tag) { + if (const TagType *TT = T->getAs<TagType>()) { + TagDecl* TD = TT->getDecl(); + + // FIXME: this location is very wrong; we really need typelocs. + SourceLocation TagLocation = TD->getTagKeywordLoc(); + + // FIXME: type might be anonymous. + IdentifierInfo *Id = TD->getIdentifier(); + + // TODO: should we even warn on struct/class mismatches for this? Seems + // like it's likely to produce a lot of spurious errors. + if (!SemaRef.isAcceptableTagRedeclaration(TD, Tag, TagLocation, *Id)) { + SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) + << Id + << CodeModificationHint::CreateReplacement(SourceRange(TagLocation), + TD->getKindName()); + SemaRef.Diag(TD->getLocation(), diag::note_previous_use); + } + } + + return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(T, Tag); +} + +Sema::OwningExprResult TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { if (!E->isTypeDependent()) return SemaRef.Owned(E->Retain()); |