aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplate.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2013-02-18 22:06:02 +0000
committerDavid Blaikie <dblaikie@gmail.com>2013-02-18 22:06:02 +0000
commit39e6ab4be93d9c5e729a578ddd9d415cd2d49872 (patch)
treefc9c9aad9c0b7b392ff2b08bb1d5df59c8d6c048 /lib/Sema/SemaTemplate.cpp
parent9ba7627d25a7555b1afff04f685d2f161974e682 (diff)
Replace TypeLoc llvm::cast support to be well-defined.
The TypeLoc hierarchy used the llvm::cast machinery to perform undefined behavior by casting pointers/references to TypeLoc objects to derived types and then using the derived copy constructors (or even returning pointers to derived types that actually point to the original TypeLoc object). Some context is in this thread: http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html Though it's spread over a few months which can be hard to read in the mail archive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175462 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r--lib/Sema/SemaTemplate.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 86af8c3a23..74a6da1947 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -6956,15 +6956,15 @@ Sema::ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T);
if (isa<DependentNameType>(T)) {
- DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc());
+ DependentNameTypeLoc TL = TSI->getTypeLoc().castAs<DependentNameTypeLoc>();
TL.setElaboratedKeywordLoc(TypenameLoc);
TL.setQualifierLoc(QualifierLoc);
TL.setNameLoc(IdLoc);
} else {
- ElaboratedTypeLoc TL = cast<ElaboratedTypeLoc>(TSI->getTypeLoc());
+ ElaboratedTypeLoc TL = TSI->getTypeLoc().castAs<ElaboratedTypeLoc>();
TL.setElaboratedKeywordLoc(TypenameLoc);
TL.setQualifierLoc(QualifierLoc);
- cast<TypeSpecTypeLoc>(TL.getNamedTypeLoc()).setNameLoc(IdLoc);
+ TL.getNamedTypeLoc().castAs<TypeSpecTypeLoc>().setNameLoc(IdLoc);
}
return CreateParsedType(T, TSI);
@@ -7054,12 +7054,12 @@ static bool isEnableIf(NestedNameSpecifierLoc NNS, const IdentifierInfo &II,
if (!NNS || !NNS.getNestedNameSpecifier()->getAsType())
return false;
TypeLoc EnableIfTy = NNS.getTypeLoc();
- TemplateSpecializationTypeLoc *EnableIfTSTLoc =
- dyn_cast<TemplateSpecializationTypeLoc>(&EnableIfTy);
- if (!EnableIfTSTLoc || EnableIfTSTLoc->getNumArgs() == 0)
+ TemplateSpecializationTypeLoc EnableIfTSTLoc =
+ EnableIfTy.getAs<TemplateSpecializationTypeLoc>();
+ if (!EnableIfTSTLoc || EnableIfTSTLoc.getNumArgs() == 0)
return false;
const TemplateSpecializationType *EnableIfTST =
- cast<TemplateSpecializationType>(EnableIfTSTLoc->getTypePtr());
+ cast<TemplateSpecializationType>(EnableIfTSTLoc.getTypePtr());
// ... which names a complete class template declaration...
const TemplateDecl *EnableIfDecl =
@@ -7074,7 +7074,7 @@ static bool isEnableIf(NestedNameSpecifierLoc NNS, const IdentifierInfo &II,
return false;
// Assume the first template argument is the condition.
- CondRange = EnableIfTSTLoc->getArgLoc(0).getSourceRange();
+ CondRange = EnableIfTSTLoc.getArgLoc(0).getSourceRange();
return true;
}