diff options
author | Anders Carlsson <andersca@mac.com> | 2011-04-10 20:33:22 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2011-04-10 20:33:22 +0000 |
commit | c602006638a659b950be676f76aa95eddbbedfb3 (patch) | |
tree | 58ca20b706dac16703011e9559a827f778b571d3 /clang/lib/Sema/SemaCXXCast.cpp | |
parent | 784ba65787175be823f2e04e097b4d5d326282a2 (diff) | |
download | bcm5719-llvm-c602006638a659b950be676f76aa95eddbbedfb3.tar.gz bcm5719-llvm-c602006638a659b950be676f76aa95eddbbedfb3.zip |
As a first step towards fixing PR9641, add a CK_DynamicToNull cast kind which
represents a dynamic cast where we know that the result is always null.
For example:
struct A {
virtual ~A();
};
struct B final : A { };
struct C { };
bool f(B* b) {
return dynamic_cast<C*>(b);
}
llvm-svn: 129256
Diffstat (limited to 'clang/lib/Sema/SemaCXXCast.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCXXCast.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp index 31a772a5d8e..52a13ef5b29 100644 --- a/clang/lib/Sema/SemaCXXCast.cpp +++ b/clang/lib/Sema/SemaCXXCast.cpp @@ -522,6 +522,14 @@ CheckDynamicCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, return; } + // If the source class is marked 'final', and the destination class does not + // derive from the source class, then we know that the result is always null. + if (SrcRecord->getDecl()->hasAttr<FinalAttr>() && + !Self.IsDerivedFrom(DestPointee, SrcPointee)) { + Kind = CK_DynamicToNull; + return; + } + // C++ 5.2.7p5 // Upcasts are resolved statically. if (DestRecord && Self.IsDerivedFrom(SrcPointee, DestPointee)) { |