Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpp2rust/converter/models/boxed_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ class AddressTakenVisitor
AddressTaken(capture.getCapturedVar());
}
}
if (expr->getLambdaClass()->isGenericLambda()) {
ForEachLambdaCallOperator(
expr->getLambdaClass(),
[&](clang::CXXMethodDecl *op) { TraverseDecl(op); });
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ADDITIONAL_COMPILE_FLAGS: -std=c++23
#include <cassert>

// N4950 [expr.prim.lambda.capture]/12: an entity is captured by reference if
// it is implicitly or explicitly captured but not captured by copy.
namespace p12_parameter_of_generic_lambda_captured_by_reference {
void test() {
auto increment_twice = [](auto n) {
auto increment = [&n] { ++n; };
increment();
increment();
return n;
};
assert(increment_twice(3) == 5);
}
} // namespace p12_parameter_of_generic_lambda_captured_by_reference

int main() {
p12_parameter_of_generic_lambda_captured_by_reference::test();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
extern crate libcc2rs;
use libcc2rs::*;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::{Read, Seek, Write};
use std::os::fd::AsFd;
use std::rc::{Rc, Weak};
pub fn test_0() {
let increment_twice: Value<FnPtr<Generic>> =
Rc::new(RefCell::new(lambda!(Generic, {}, |n: i32| -> i32 {
let n: Value<i32> = Rc::new(RefCell::new(n));
let increment: Value<FnPtr<fn()>> = Rc::new(RefCell::new(lambda!(
{
let n: Ptr<i32> = n.as_pointer();
},
|| {
n.with_mut(|__v| __v.prefix_inc());
}
)));
({ (*increment.borrow()).call() });
({ (*increment.borrow()).call() });
return (*n.borrow());
})));
assert!(
({
(({
(*increment_twice.borrow())
.spec::<fn(i32) -> i32>(0)
.call(3)
}) == 5)
})
);
}
pub fn main() {
__cpp2rust_init_globals();
std::process::exit(main_0());
}
fn main_0() -> i32 {
({ test_0() });
return 0;
}
pub fn __cpp2rust_init_globals() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern crate libc;
use libc::*;
extern crate libcc2rs;
use libcc2rs::*;
use std::collections::BTreeMap;
use std::io::{Read, Seek, Write};
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub unsafe fn test_0() {
let mut increment_twice: FnPtr<Generic> = lambda_unsafe!(Generic, {}, |mut n: i32| -> i32 {
let mut increment: FnPtr<fn()> = lambda_unsafe!(
{
let n: *mut i32 = &mut n;
},
|| {
(*n).prefix_inc();
}
);
(unsafe { increment.call() });
(unsafe { increment.call() });
return n;
});
assert!(((unsafe { increment_twice.spec::<fn(i32) -> i32>(0).call(3,) }) == (5)));
}
pub fn main() {
unsafe {
__cpp2rust_init_globals();
std::process::exit(main_0() as i32);
}
}
unsafe fn main_0() -> i32 {
(unsafe { test_0() });
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
Loading