File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ use std::io::prelude::*;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: AsFd ;
88use std:: rc:: { Rc , Weak } ;
9+ pub fn foo_0 ( str : Ptr < u8 > ) {
10+ let str: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( str) ) ;
11+ }
912pub fn main ( ) {
1013 std:: process:: exit ( main_0 ( ) ) ;
1114}
@@ -22,5 +25,13 @@ fn main_0() -> i32 {
2225 ] ) ) ) ;
2326 let mutable_string: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( Ptr :: from_string_literal ( "hello" ) ) ) ;
2427 let immutable_string: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( Ptr :: from_string_literal ( "hello" ) ) ) ;
28+ ( {
29+ let _str: Ptr < u8 > = Ptr :: from_string_literal ( "world" ) ;
30+ foo_0 ( _str)
31+ } ) ;
32+ ( {
33+ let _str: Ptr < u8 > = ( * mutable_string. borrow ( ) ) . clone ( ) ;
34+ foo_0 ( _str)
35+ } ) ;
2536 return 0 ;
2637}
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 foo_0 ( str : Ptr < u8 > ) {
10+ let str: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( str) ) ;
11+ }
12+ pub fn main ( ) {
13+ std:: process:: exit ( main_0 ( ) ) ;
14+ }
15+ fn main_0 ( ) -> i32 {
16+ let mutable_strings: Value < Box < [ Ptr < u8 > ] > > = Rc :: new ( RefCell :: new ( Box :: new ( [
17+ Ptr :: from_string_literal ( "a" ) ,
18+ Ptr :: from_string_literal ( "b" ) ,
19+ Ptr :: from_string_literal ( "c" ) ,
20+ ] ) ) ) ;
21+ let immutable_strings: Value < Box < [ Ptr < u8 > ] > > = Rc :: new ( RefCell :: new ( Box :: new ( [
22+ Ptr :: from_string_literal ( "a" ) ,
23+ Ptr :: from_string_literal ( "b" ) ,
24+ Ptr :: from_string_literal ( "c" ) ,
25+ ] ) ) ) ;
26+ let mutable_string: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( Ptr :: from_string_literal ( "hello" ) ) ) ;
27+ let immutable_string: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( Ptr :: from_string_literal ( "hello" ) ) ) ;
28+ ( {
29+ let _str: Ptr < u8 > = Ptr :: from_string_literal ( "world" ) ;
30+ foo_0 ( _str)
31+ } ) ;
32+ ( {
33+ let _str: Ptr < u8 > = ( * mutable_string. borrow ( ) ) . clone ( ) ;
34+ foo_0 ( _str)
35+ } ) ;
36+ return 0 ;
37+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use std::collections::BTreeMap;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
88use std:: rc:: Rc ;
9+ pub unsafe fn foo_0 ( mut str : * mut u8 ) { }
910pub fn main ( ) {
1011 unsafe {
1112 std:: process:: exit ( main_0 ( ) as i32 ) ;
@@ -20,5 +21,13 @@ unsafe fn main_0() -> i32 {
2021 let mut immutable_strings: [ * const u8 ; 3 ] = [ b"a\0 " . as_ptr ( ) , b"b\0 " . as_ptr ( ) , b"c\0 " . as_ptr ( ) ] ;
2122 let mut mutable_string: * mut u8 = b"hello\0 " . as_ptr ( ) . cast_mut ( ) ;
2223 let mut immutable_string: * const u8 = b"hello\0 " . as_ptr ( ) ;
24+ ( unsafe {
25+ let _str: * mut u8 = b"world\0 " . as_ptr ( ) . cast_mut ( ) ;
26+ foo_0 ( _str)
27+ } ) ;
28+ ( unsafe {
29+ let _str: * mut u8 = mutable_string;
30+ foo_0 ( _str)
31+ } ) ;
2332 return 0 ;
2433}
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 foo_0 ( mut str : * mut u8 ) { }
10+ pub fn main ( ) {
11+ unsafe {
12+ std:: process:: exit ( main_0 ( ) as i32 ) ;
13+ }
14+ }
15+ unsafe fn main_0 ( ) -> i32 {
16+ let mut mutable_strings: [ * mut u8 ; 3 ] = [
17+ b"a\0 " . as_ptr ( ) . cast_mut ( ) ,
18+ b"b\0 " . as_ptr ( ) . cast_mut ( ) ,
19+ b"c\0 " . as_ptr ( ) . cast_mut ( ) ,
20+ ] ;
21+ let mut immutable_strings: [ * const u8 ; 3 ] = [
22+ b"a\0 " . as_ptr ( ) . cast_mut ( ) ,
23+ b"b\0 " . as_ptr ( ) . cast_mut ( ) ,
24+ b"c\0 " . as_ptr ( ) . cast_mut ( ) ,
25+ ] ;
26+ let mut mutable_string: * mut u8 = b"hello\0 " . as_ptr ( ) . cast_mut ( ) ;
27+ let mut immutable_string: * const u8 = b"hello\0 " . as_ptr ( ) . cast_mut ( ) ;
28+ ( unsafe {
29+ let _str: * mut u8 = b"world\0 " . as_ptr ( ) . cast_mut ( ) ;
30+ foo_0 ( _str)
31+ } ) ;
32+ ( unsafe {
33+ let _str: * mut u8 = mutable_string;
34+ foo_0 ( _str)
35+ } ) ;
36+ return 0 ;
37+ }
Original file line number Diff line number Diff line change 1+ void foo (char *str) {}
2+
13int main () {
4+ // warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
25 char *mutable_strings[] = {" a" , " b" , " c" };
36 const char *immutable_strings[] = {" a" , " b" , " c" };
47
58 char *mutable_string = " hello" ;
69 const char *immutable_string = " hello" ;
10+
11+ foo (" world" );
12+ foo (mutable_string);
13+ // This is not allowed, only string literals to char* are allowed: foo(immutable_string);
714 return 0 ;
815}
Original file line number Diff line number Diff line change 1+ void foo (char * str ) {}
2+
3+ int main () {
4+ // warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
5+ char * mutable_strings [] = {"a" , "b" , "c" };
6+ const char * immutable_strings [] = {"a" , "b" , "c" };
7+
8+ char * mutable_string = "hello" ;
9+ const char * immutable_string = "hello" ;
10+
11+ foo ("world" );
12+ foo (mutable_string );
13+ // This is not allowed, only string literals to char* are allowed: foo(immutable_string);
14+ return 0 ;
15+ }
You can’t perform that action at this time.
0 commit comments