[cfe-commits] r77905 - in /cfe/trunk: include/clang/AST/Expr.h lib/Sema/SemaCXXCast.cpp

Anders Carlsson andersca at mac.com
Sun Aug 2 12:07:59 PDT 2009


Author: andersca
Date: Sun Aug  2 14:07:59 2009
New Revision: 77905

URL: http://llvm.org/viewvc/llvm-project?rev=77905&view=rev
Log:
Use the correct cast kind for dynamic_cast.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/Sema/SemaCXXCast.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=77905&r1=77904&r2=77905&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Aug  2 14:07:59 2009
@@ -1170,7 +1170,10 @@
     CK_NoOp,
     
     /// CK_DerivedToBase - Derived to base class casts.
-    CK_DerivedToBase
+    CK_DerivedToBase,
+    
+    /// CK_Dynamic - Dynamic cast.
+    CK_Dynamic
   };
   
 private:

Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=77905&r1=77904&r2=77905&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Sun Aug  2 14:07:59 2009
@@ -45,7 +45,8 @@
                             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 @@
     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 @@
 /// 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 @@
   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 @@
   }
 
   // Done. Everything else is run-time checks.
+  Kind = CastExpr::CK_Dynamic;
 }
 
 /// CheckConstCast - Check that a const_cast\<DestType\>(SrcExpr) is valid.





More information about the cfe-commits mailing list