diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 08a4a827..99f51b92 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -274,6 +274,13 @@ class Converter : public clang::RecursiveASTVisitor { // Option implements Copy virtual bool FunctionPointerImplementsCopy() const { return true; } + bool TypeIsCopyable(clang::QualType ty) const { + if (ty->isFunctionPointerType() || ty->isFunctionType()) { + return FunctionPointerImplementsCopy(); + } + return ty->isIntegerType(); + } + virtual void ConvertPrintf(clang::CallExpr *expr); void ConvertVAArgCall(clang::CallExpr *expr); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 6d335e29..1927e591 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1104,9 +1104,4 @@ ConstCastType GetConstCastType(clang::QualType to, clang::QualType from) { } } -bool TypeIsCopyable(clang::QualType ty) { - return ty->isIntegerType() || ty->isFunctionPointerType() || - ty->isFunctionType(); -} - } // namespace cpp2rust diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 110b501d..291873cc 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -223,6 +223,4 @@ enum class ConstCastType { ConstCastType GetConstCastType(clang::QualType to, clang::QualType from); -bool TypeIsCopyable(clang::QualType ty); - } // namespace cpp2rust diff --git a/tests/unit/out/refcount/va_arg_fn_ptr.rs b/tests/unit/out/refcount/va_arg_fn_ptr.rs index 3e2e477c..bca43c74 100644 --- a/tests/unit/out/refcount/va_arg_fn_ptr.rs +++ b/tests/unit/out/refcount/va_arg_fn_ptr.rs @@ -42,6 +42,15 @@ pub fn apply_binary_4(a: i32, b: i32, __args: &[VaArg]) -> i32 { )); return (*result.borrow()); } +pub fn not_supported_5(ctx: AnyPtr, fn_: FnPtr i32>, extra: AnyPtr) -> i32 { + let ctx: Value = Rc::new(RefCell::new(ctx)); + let fn_: Value i32>> = Rc::new(RefCell::new(fn_)); + let extra: Value = Rc::new(RefCell::new(extra)); + (*ctx.borrow()).clone(); + (*fn_.borrow()).clone(); + (*extra.borrow()).clone(); + return -3_i32; +} pub fn main() { std::process::exit(main_0()); } @@ -61,5 +70,14 @@ fn main_0() -> i32 { as i32) != 0) ); + let dummy: Value = Rc::new(RefCell::new(0)); + assert!( + (((({ + let _ctx: AnyPtr = ((dummy.as_pointer()) as Ptr).to_any(); + let _extra: AnyPtr = ((dummy.as_pointer()) as Ptr).to_any(); + not_supported_5(_ctx, FnPtr:: i32>::new(square_0), _extra) + }) == -3_i32) as i32) + != 0) + ); return 0; } diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 0933260f..77724cab 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -104,11 +104,11 @@ fn main_0() -> i32 { })); assert!(((*err.borrow()) == 7)); assert!(((*chosen.borrow()) == 123)); - bump_and_return_4; + bump_and_return_4.clone(); assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2)); - (FnPtr:: i32>::new(bump_and_return_4)); + (FnPtr:: i32>::new(bump_and_return_4)).clone(); assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2)); - ((FnPtr:: i32>::new(bump_and_return_4)).cast:: i32>(None)); + ((FnPtr:: i32>::new(bump_and_return_4)).cast:: i32>(None)).clone(); assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2)); let storage: Value = Rc::new(RefCell::new(11)); let p: Value> = Rc::new(RefCell::new((storage.as_pointer()))); diff --git a/tests/unit/out/unsafe/va_arg_fn_ptr.rs b/tests/unit/out/unsafe/va_arg_fn_ptr.rs index 6a4a4e16..a02eea3d 100644 --- a/tests/unit/out/unsafe/va_arg_fn_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_fn_ptr.rs @@ -35,6 +35,16 @@ pub unsafe fn apply_binary_4(mut a: i32, mut b: i32, __args: &[VaArg]) -> i32 { let mut result: i32 = (unsafe { (fn_).unwrap()(a, b) }); return result; } +pub unsafe fn not_supported_5( + mut ctx: *mut ::libc::c_void, + mut fn_: Option i32>, + mut extra: *mut ::libc::c_void, +) -> i32 { + &(ctx); + &(fn_); + &(extra); + return -3_i32; +} pub fn main() { unsafe { std::process::exit(main_0() as i32); @@ -78,5 +88,16 @@ unsafe fn main_0() -> i32 { }) == (7)) as i32) != 0) ); + let mut dummy: i32 = 0; + assert!( + ((((unsafe { + let _ctx: *mut ::libc::c_void = + ((&mut dummy as *mut i32) as *mut i32 as *mut ::libc::c_void); + let _extra: *mut ::libc::c_void = + ((&mut dummy as *mut i32) as *mut i32 as *mut ::libc::c_void); + not_supported_5(_ctx, Some(square_0), _extra) + }) == (-3_i32)) as i32) + != 0) + ); return 0; } diff --git a/tests/unit/va_arg_fn_ptr.c b/tests/unit/va_arg_fn_ptr.c index bf547808..36e209e9 100644 --- a/tests/unit/va_arg_fn_ptr.c +++ b/tests/unit/va_arg_fn_ptr.c @@ -26,9 +26,18 @@ int apply_binary(int a, int b, ...) { return result; } +static int not_supported(void *ctx, unary fn, void *extra) { + (void)ctx; + (void)fn; + (void)extra; + return -3; +} + int main() { assert(apply_unary(5, square) == 25); assert(apply_unary(7, negate) == -7); assert(apply_binary(3, 4, add) == 7); + int dummy = 0; + assert(not_supported(&dummy, square, &dummy) == -3); return 0; }