File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < cassert>
2+ #include < type_traits>
3+
4+ template <typename T> int classify (T x) {
5+ if constexpr (std::is_pointer_v<T>) {
6+ return *x;
7+ } else if constexpr (sizeof (T) > 4 ) {
8+ return 2 ;
9+ }
10+ return 1 ;
11+ }
12+
13+ int main () {
14+ int v = 7 ;
15+ assert (classify (&v) == 7 );
16+ assert (classify (1L ) == 2 );
17+ assert (classify (1 ) == 1 );
18+ return 0 ;
19+ }
Original file line number Diff line number Diff line change 1+ extern crate libcc2rs;
2+ use libcc2rs:: * ;
3+ use std:: cell:: RefCell ;
4+ use std:: collections:: BTreeMap ;
5+ use std:: io:: prelude:: * ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: AsFd ;
8+ use std:: rc:: { Rc , Weak } ;
9+ pub fn classify_0 ( x : Ptr < i32 > ) -> i32 {
10+ let x: Value < Ptr < i32 > > = Rc :: new ( RefCell :: new ( x) ) ;
11+ {
12+ return ( ( * x. borrow ( ) ) . read ( ) ) ;
13+ }
14+ return 1 ;
15+ }
16+ pub fn classify_1 ( x : i64 ) -> i32 {
17+ let x: Value < i64 > = Rc :: new ( RefCell :: new ( x) ) ;
18+ {
19+ return 2 ;
20+ }
21+ return 1 ;
22+ }
23+ pub fn classify_2 ( x : i32 ) -> i32 {
24+ let x: Value < i32 > = Rc :: new ( RefCell :: new ( x) ) ;
25+ return 1 ;
26+ }
27+ pub fn main ( ) {
28+ std:: process:: exit ( main_0 ( ) ) ;
29+ }
30+ fn main_0 ( ) -> i32 {
31+ let v: Value < i32 > = Rc :: new ( RefCell :: new ( 7 ) ) ;
32+ assert ! ( ( ( { classify_0( ( v. as_pointer( ) ) , ) } ) == 7 ) ) ;
33+ assert ! ( ( ( { classify_1( 1_i64 , ) } ) == 2 ) ) ;
34+ assert ! ( ( ( { classify_2( 1 , ) } ) == 1 ) ) ;
35+ return 0 ;
36+ }
Original file line number Diff line number Diff line change 1+ extern crate libc;
2+ use libc:: * ;
3+ extern crate libcc2rs;
4+ use libcc2rs:: * ;
5+ use std:: collections:: BTreeMap ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
8+ use std:: rc:: Rc ;
9+ pub unsafe fn classify_0 ( mut x : * mut i32 ) -> i32 {
10+ {
11+ return ( * x) ;
12+ }
13+ return 1 ;
14+ }
15+ pub unsafe fn classify_1 ( mut x : i64 ) -> i32 {
16+ {
17+ return 2 ;
18+ }
19+ return 1 ;
20+ }
21+ pub unsafe fn classify_2 ( mut x : i32 ) -> i32 {
22+ return 1 ;
23+ }
24+ pub fn main ( ) {
25+ unsafe {
26+ std:: process:: exit ( main_0 ( ) as i32 ) ;
27+ }
28+ }
29+ unsafe fn main_0 ( ) -> i32 {
30+ let mut v: i32 = 7 ;
31+ assert ! ( ( ( unsafe { classify_0( ( & mut v as * mut i32 ) , ) } ) == ( 7 ) ) ) ;
32+ assert ! ( ( ( unsafe { classify_1( 1_i64 , ) } ) == ( 2 ) ) ) ;
33+ assert ! ( ( ( unsafe { classify_2( 1 , ) } ) == ( 1 ) ) ) ;
34+ return 0 ;
35+ }
You can’t perform that action at this time.
0 commit comments