File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2579,6 +2579,13 @@ bool Converter::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {
25792579 return false ;
25802580 }
25812581 switch (expr->getStmtClass ()) {
2582+ case clang::Stmt::CXXFunctionalCastExprClass:
2583+ if (type->isEnumeralType () && !sub_expr->getType ()->isEnumeralType ()) {
2584+ ConvertIntegerToEnumeralCast (expr, sub_expr);
2585+ return false ;
2586+ }
2587+ Convert (sub_expr, type);
2588+ return false ;
25822589 case clang::Stmt::CXXReinterpretCastExprClass:
25832590 case clang::Stmt::CXXStaticCastExprClass:
25842591 case clang::Stmt::CStyleCastExprClass:
Original file line number Diff line number Diff line change @@ -1482,6 +1482,8 @@ bool ConverterRefCount::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {
14821482 return false ;
14831483 }
14841484 return Converter::VisitExplicitCastExpr (expr);
1485+ case clang::Stmt::CXXFunctionalCastExprClass:
1486+ return Converter::VisitExplicitCastExpr (expr);
14851487 default :
14861488 return Convert (expr->getSubExpr ());
14871489 }
Original file line number Diff line number Diff line change 11#include < cassert>
22#include < cstdlib>
33
4+ enum E { A, B, C };
5+
46int main () {
57 size_t size = 1 ;
68 assert (size == 1 );
9+
10+ unsigned long ul = 5 ;
11+ size_t s1 = size_t (ul);
12+ assert (s1 == 5 );
13+ ul = (unsigned long )size_t (7 );
14+ assert (ul == 7 );
15+
16+ int i = 2 ;
17+ E e = E (i);
18+ assert (e == C);
19+ assert (int (e) == 2 );
720 return 0 ;
821}
Original file line number Diff line number Diff line change @@ -14,24 +14,24 @@ fn main_0() -> i32 {
1414 let b1: Value < u8 > = Rc :: new ( RefCell :: new ( 1_u8 ) ) ;
1515 let ushift1: Value < u32 > = Rc :: new ( RefCell :: new ( 3_u32 ) ) ;
1616 let shl1: Value < u8 > = Rc :: new ( RefCell :: new ( ( * b1. borrow ( ) ) << ( * ushift1. borrow ( ) ) ) ) ;
17- assert ! ( ( ( * shl1. borrow( ) ) == 8 ) ) ;
17+ assert ! ( ( ( * shl1. borrow( ) ) == ( ( 8 ) as u8 ) ) ) ;
1818 let ushift2: Value < u32 > = Rc :: new ( RefCell :: new ( 2_u32 ) ) ;
1919 let shr1: Value < u8 > = Rc :: new ( RefCell :: new ( ( * shl1. borrow ( ) ) >> ( * ushift2. borrow ( ) ) ) ) ;
20- assert ! ( ( ( * shr1. borrow( ) ) == 2 ) ) ;
20+ assert ! ( ( ( * shr1. borrow( ) ) == ( ( 2 ) as u8 ) ) ) ;
2121 let ushift3: Value < u32 > = Rc :: new ( RefCell :: new ( 5_u32 ) ) ;
2222 {
2323 let n_ = ( * b1. borrow ( ) ) << ( * ushift3. borrow ( ) ) ;
2424 ( * b1. borrow_mut ( ) ) = n_;
2525 ( * b1. borrow ( ) )
2626 } ;
27- assert ! ( ( ( * b1. borrow( ) ) == 32 ) ) ;
27+ assert ! ( ( ( * b1. borrow( ) ) == ( ( 32 ) as u8 ) ) ) ;
2828 let ushift4: Value < u32 > = Rc :: new ( RefCell :: new ( 3_u32 ) ) ;
2929 {
3030 let n_ = ( * b1. borrow ( ) ) >> ( * ushift4. borrow ( ) ) ;
3131 ( * b1. borrow_mut ( ) ) = n_;
3232 ( * b1. borrow ( ) )
3333 } ;
34- assert ! ( ( ( * b1. borrow( ) ) == 4 ) ) ;
34+ assert ! ( ( ( * b1. borrow( ) ) == ( ( 4 ) as u8 ) ) ) ;
3535 return 0 ;
3636}
3737pub fn __cpp2rust_init_globals ( ) { }
Original file line number Diff line number Diff line change @@ -6,13 +6,26 @@ use std::io::prelude::*;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: AsFd ;
88use std:: rc:: { Rc , Weak } ;
9+ pub type E = u32 ;
10+ pub const E_A : E = 0 ;
11+ pub const E_B : E = 1 ;
12+ pub const E_C : E = 2 ;
913pub fn main ( ) {
1014 __cpp2rust_init_globals ( ) ;
1115 std:: process:: exit ( main_0 ( ) ) ;
1216}
1317fn main_0 ( ) -> i32 {
1418 let size: Value < usize > = Rc :: new ( RefCell :: new ( 1_usize ) ) ;
1519 assert ! ( ( ( * size. borrow( ) ) == 1_usize ) ) ;
20+ let ul: Value < u64 > = Rc :: new ( RefCell :: new ( 5_u64 ) ) ;
21+ let s1: Value < usize > = Rc :: new ( RefCell :: new ( ( ( * ul. borrow ( ) ) as usize ) ) ) ;
22+ assert ! ( ( ( * s1. borrow( ) ) == 5_usize ) ) ;
23+ ( * ul. borrow_mut ( ) ) = ( 7_usize as u64 ) ;
24+ assert ! ( ( ( * ul. borrow( ) ) == 7_u64 ) ) ;
25+ let i: Value < i32 > = Rc :: new ( RefCell :: new ( 2 ) ) ;
26+ let e: Value < E > = Rc :: new ( RefCell :: new ( ( ( * i. borrow ( ) ) as E ) ) ) ;
27+ assert ! ( ( ( ( * e. borrow( ) ) as i32 ) == ( E_C as i32 ) ) ) ;
28+ assert ! ( ( ( ( * e. borrow( ) ) as i32 ) == 2 ) ) ;
1629 return 0 ;
1730}
1831pub fn __cpp2rust_init_globals ( ) { }
Original file line number Diff line number Diff line change @@ -16,24 +16,24 @@ unsafe fn main_0() -> i32 {
1616 let mut b1: u8 = 1_u8 ;
1717 let mut ushift1: u32 = 3_u32 ;
1818 let mut shl1: u8 = b1 << ushift1;
19- assert ! ( ( ( shl1) == ( 8 ) ) ) ;
19+ assert ! ( ( ( shl1) == ( ( 8 ) as u8 ) ) ) ;
2020 let mut ushift2: u32 = 2_u32 ;
2121 let mut shr1: u8 = shl1 >> ushift2;
22- assert ! ( ( ( shr1) == ( 2 ) ) ) ;
22+ assert ! ( ( ( shr1) == ( ( 2 ) as u8 ) ) ) ;
2323 let mut ushift3: u32 = 5_u32 ;
2424 {
2525 let n_ = b1 << ushift3;
2626 b1 = n_;
2727 b1
2828 } ;
29- assert ! ( ( ( b1) == ( 32 ) ) ) ;
29+ assert ! ( ( ( b1) == ( ( 32 ) as u8 ) ) ) ;
3030 let mut ushift4: u32 = 3_u32 ;
3131 {
3232 let n_ = b1 >> ushift4;
3333 b1 = n_;
3434 b1
3535 } ;
36- assert ! ( ( ( b1) == ( 4 ) ) ) ;
36+ assert ! ( ( ( b1) == ( ( 4 ) as u8 ) ) ) ;
3737 return 0 ;
3838}
3939pub unsafe fn __cpp2rust_init_globals ( ) { }
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ use std::collections::BTreeMap;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
88use std:: rc:: Rc ;
9+ pub type E = u32 ;
10+ pub const E_A : E = 0 ;
11+ pub const E_B : E = 1 ;
12+ pub const E_C : E = 2 ;
913pub fn main ( ) {
1014 unsafe {
1115 __cpp2rust_init_globals ( ) ;
@@ -15,6 +19,15 @@ pub fn main() {
1519unsafe fn main_0 ( ) -> i32 {
1620 let mut size: usize = 1_usize ;
1721 assert ! ( ( ( size) == ( 1_usize ) ) ) ;
22+ let mut ul: u64 = 5_u64 ;
23+ let mut s1: usize = ( ul as usize ) ;
24+ assert ! ( ( ( s1) == ( 5_usize ) ) ) ;
25+ ul = ( 7_usize as u64 ) ;
26+ assert ! ( ( ( ul) == ( 7_u64 ) ) ) ;
27+ let mut i: i32 = 2 ;
28+ let mut e: E = ( ( i) as E ) ;
29+ assert ! ( ( ( e as i32 ) == ( E_C as i32 ) ) ) ;
30+ assert ! ( ( ( e as i32 ) == ( 2 ) ) ) ;
1831 return 0 ;
1932}
2033pub unsafe fn __cpp2rust_init_globals ( ) { }
You can’t perform that action at this time.
0 commit comments