aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaCXXCast.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaCXXCast.cpp')
-rw-r--r--lib/Sema/SemaCXXCast.cpp8
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)) {