@@ -90,12 +90,16 @@ static std::string AccessToStringWithColon(const AccessSpecifier& access)
9090
9191using namespace asthelpers ;
9292
93- static std::string_view GetCastName (const CastKind castKind)
93+ static std::string_view GetCastName (const CastKind castKind, bool constnessChange = false )
9494{
9595 if (is{castKind}.any_of (CastKind::CK_BitCast, CastKind::CK_IntegralToPointer, CastKind::CK_PointerToIntegral)) {
9696 return kwReinterpretCast;
9797 }
9898
99+ if ((CastKind::CK_NoOp == castKind) and constnessChange) {
100+ return " const_cast" sv;
101+ }
102+
99103 return kwStaticCast;
100104}
101105// -----------------------------------------------------------------------------
@@ -2482,11 +2486,26 @@ void CodeGenerator::InsertArg(const ForStmt* stmt)
24822486}
24832487// -----------------------------------------------------------------------------
24842488
2489+ static bool IsConstQualifiedType (QualType type)
2490+ {
2491+ if (not type.isNull ()) {
2492+ if (auto * typePtr = type.getTypePtrOrNull ()) {
2493+ if (auto pointee = typePtr->getPointeeType (); not pointee.isNull ()) {
2494+ return pointee.isConstQualified ();
2495+ }
2496+ }
2497+ }
2498+
2499+ return false ;
2500+ }
2501+ // -----------------------------------------------------------------------------
2502+
24852503void CodeGenerator::InsertArg (const CStyleCastExpr* stmt)
24862504{
24872505 const auto castKind = stmt->getCastKind ();
2488- const auto castName = GetCastName (castKind);
24892506 const QualType castDestType = stmt->getType ().getCanonicalType ();
2507+ const auto castName = GetCastName (
2508+ castKind, IsConstQualifiedType (castDestType) != IsConstQualifiedType (stmt->getSubExpr ()->getType ()));
24902509
24912510 FormatCast (castName, castDestType, stmt->getSubExpr (), castKind);
24922511}
0 commit comments