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 | 7d99bc37e77157523e3bfbc6c077842b74e6690f (patch) | |
tree | f7abc6739dafe6154c2cf073e8dc3fd39306bf24 /lib/Sema/SemaCXXCast.cpp | |
parent | fb8721ce4c6fef3739b1cbd1e38e3f1949462033 (diff) |
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);
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129256 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCXXCast.cpp')
-rw-r--r-- | lib/Sema/SemaCXXCast.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index 31a772a5d8..52a13ef5b2 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/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)) { |