]> granicus.if.org Git - clang/commitdiff
Use the correct cast kind for dynamic_cast.
authorAnders Carlsson <andersca@mac.com>
Sun, 2 Aug 2009 19:07:59 +0000 (19:07 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 2 Aug 2009 19:07:59 +0000 (19:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77905 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/Sema/SemaCXXCast.cpp

index 29c2386a2f31bed273e738c70072c7842e6f3e6a..3cec4e8aaf5662818e242f79437fdf866d6646fb 100644 (file)
@@ -1170,7 +1170,10 @@ public:
     CK_NoOp,
     
     /// CK_DerivedToBase - Derived to base class casts.
-    CK_DerivedToBase
+    CK_DerivedToBase,
+    
+    /// CK_Dynamic - Dynamic cast.
+    CK_Dynamic
   };
   
 private:
index afe539cd46570ac9836eaf9c058212652664a688..254af541710d5c3dba93d30409fc3306bcc1e08f 100644 (file)
@@ -45,7 +45,8 @@ static void CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
                             const SourceRange &OpRange);
 static void CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
                              const SourceRange &OpRange,
-                             const SourceRange &DestRange);
+                             const SourceRange &DestRange, 
+                             CastExpr::CastKind &Kind);
 
 static bool CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType);
 
@@ -119,13 +120,13 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
     return Owned(new (Context) CXXConstCastExpr(DestType.getNonReferenceType(),
                                                 Ex, DestType, OpLoc));
 
-  case tok::kw_dynamic_cast:
+  case tok::kw_dynamic_cast: {
+    CastExpr::CastKind Kind = CastExpr::CK_Unknown;
     if (!TypeDependent)
-      CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
+      CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange, Kind);
     return Owned(new (Context)CXXDynamicCastExpr(DestType.getNonReferenceType(),
-                                                 CastExpr::CK_Unknown, Ex, 
-                                                 DestType, OpLoc));
-
+                                                 Kind, Ex, DestType, OpLoc));
+  }
   case tok::kw_reinterpret_cast:
     if (!TypeDependent)
       CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
@@ -192,10 +193,10 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType)
 /// CheckDynamicCast - Check that a dynamic_cast\<DestType\>(SrcExpr) is valid.
 /// Refer to C++ 5.2.7 for details. Dynamic casts are used mostly for runtime-
 /// checked downcasts in class hierarchies.
-void
+static void
 CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
                  const SourceRange &OpRange,
-                 const SourceRange &DestRange)
+                 const SourceRange &DestRange, CastExpr::CastKind &Kind)
 {
   QualType OrigDestType = DestType, OrigSrcType = SrcExpr->getType();
   DestType = Self.Context.getCanonicalType(DestType);
@@ -292,6 +293,7 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
   if (DestRecord && Self.IsDerivedFrom(SrcPointee, DestPointee)) {
     Self.CheckDerivedToBaseConversion(SrcPointee, DestPointee,
                                       OpRange.getBegin(), OpRange);
+    Kind = CastExpr::CK_DerivedToBase;
     // Diagnostic already emitted on error.
     return;
   }
@@ -305,6 +307,7 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
   }
 
   // Done. Everything else is run-time checks.
+  Kind = CastExpr::CK_Dynamic;
 }
 
 /// CheckConstCast - Check that a const_cast\<DestType\>(SrcExpr) is valid.