@@ -3058,11 +3058,10 @@ impl<'c> Translation<'c> {
30583058 CDeclKind :: EnumConstant { .. } => {
30593059 // If the variable is actually an `EnumConstant`, we need to add a cast to
30603060 // the expected integral type.
3061- if !self . enum_constant_matches_type (
3062- override_ty. unwrap_or ( qual_ty) . ctype ,
3063- decl_id,
3064- ) {
3065- val = self . convert_cast_from_enum ( qual_ty. ctype , val) ?;
3061+ let target_type_id = override_ty. unwrap_or ( qual_ty) ;
3062+
3063+ if !self . enum_constant_matches_type ( target_type_id. ctype , decl_id) {
3064+ val = self . convert_cast_from_enum ( target_type_id. ctype , val) ?;
30663065 }
30673066
30683067 return Ok ( WithStmts :: new_val ( val) ) ;
@@ -3479,6 +3478,18 @@ impl<'c> Translation<'c> {
34793478 if self . enum_constant_matches_type ( target_type_id. ctype , decl_id) {
34803479 return true ;
34813480 }
3481+
3482+ let source_enum_id = self . ast_context . parents [ & decl_id] ;
3483+ let source_integral_type_id = self . enum_integral_type ( source_enum_id) ;
3484+ let target_type_resolved_id = self
3485+ . ast_context
3486+ . resolve_type_id_no_typedef ( target_type_id. ctype ) ;
3487+
3488+ // Likewise, if we are casting to the inner integral type of the enum, then
3489+ // translate the enum constant directly as that.
3490+ if target_type_resolved_id == source_integral_type_id. ctype {
3491+ return true ;
3492+ }
34823493 }
34833494 }
34843495
0 commit comments