Global mapped-call temporaries produce Rust that cannot compile

perfloop-oss/cpp2rust · Uncatalogued correctness

https://perfloop.ai/t/oss/case_shwzdhwkg0

Verdict

VERIFIED · settled 2026-11-19 · merged as Cpp2Rust/cpp2rust#665

What happened: The check fails before this change and passes with it.

Hypothesis

Mapped calls with temporary arguments can make valid namespace-scope initializers fail to compile in default refcount output. Even std::min(0, 0) produces invalid static declarations for its temporary operands. Consumer prevalence is unknown, and the check did not reach a runtime lifetime observation.

ConvertCallExpr collects reference-binding temporary arguments and passes their context into GetMappedAsString. Its no-capture route forwards that context to ConvertIRFragment at lines 5187-5189. Literal operands need no evaluation-once capture, so temporary materialization remains responsible for their storage. ConverterRefCount::MaterializeTemp at cpp2rust/converter/models/converter_refcount.cpp:510-530 sees in_const_initializer_ and emits ordinary static Value<i32> bindings initialized with Rc::new. It then generates name.with(Value::as_pointer), which requires a thread-local key, not an ordinary Rc value. These declarations are inside the outer global initializer's block; they are not themselves thread_local declarations.

checkProperty(prop_r06vdkmg4k) at 3ec3713aa3177d7767b65838ad83477f3a251638 ran python3 tests/property/mapped_call_result_laws/check.py temporary and exited 1 after reaching a semantic input. Native C++ completed the first 36 global/local literal observations. The emitted refcount file failed compilation, so neither its runtime results nor the later scalar-call, object-call, nested or unsafe families were observed. Reduction independently confirmed one namespace-scope int initialized with std::min(0, 0): native prints zero; emitted Rust fails with E0277 for a non-Sync Rc static, E0599 for .with on Rc, and E0015 for non-constant Rc construction. The exact native replay and diagnostics are retained on the property node.

This used LLVM 22.1.8 and repository-pinned Rust 1.99.0, with only an unused newer AST-parameter forward declaration for test-build compatibility. An earlier run stopped before the fixture because a cached dependency header was absent. That setup failure was not counted as a defect. Preparation was repaired using the dependency's exported header paths and the existing rules/build.rs copy transformations, without editing product source or manifests.

The C++ f16/f17 rules explicitly expose const-reference min/max calls, and GetMappedAsString promises statement-length lifetimes for argument temporaries. README.md exposes the default refcount CLI without excluding namespace-scope calls. The smallest useful Case check is the saved replay, then local temporary controls and additional initializer operands. Confirmation requires compiling output with the native selected value and source-valid lifetime, without extending every call temporary to global storage. The independent identity property prop_8yx0vjyadr completed all 144 finite live-lvalue observations in both models; it is a compatibility control, not evidence that temporary operands work.

This differs from hyp_9sxs1r3x7a's missing namespace operand captures. The reduced input has no operand effects and requires no capture; removing only the curr_function_ gate does not change its empty capture set or its static materialization. It also differs from hyp_znnjma4v5y's discarded-reference move. The local receiver repairs user:4 reported fixed by the completed https://github.com/Cpp2Rust/cpp2rust/issues/575 implementation are not being reopened.

The refreshed upstream set contains https://github.com/Cpp2Rust/cpp2rust/pull/561 and https://github.com/Cpp2Rust/cpp2rust/pull/579. #561's freshly examined converter hunk at head 14d0fc3f55a502d80606b233684666b610cdf87d changes return-type comparison for rule matching, not temporary storage. #579's examined algorithm hunk changes stream f13 types and does not touch this lowering or materialization helper. Neither implements or owns this initializer-temporary repair.

Change to test: Give reference-binding call temporaries valid initializer-local storage when they are needed only through the containing full expression, rather than emitting them as ordinary Rust statics. Keep genuine C++ lifetime extension and the enclosing global variable's storage separate from these temporary operands.

Where it lives

perfloop-oss/cpp2rust · cpp2rust/converter/converter.cpp

Evidence

The check fails before this change and passes with it: `For the fixed scalar and trivially copyable-record min/max fixtures, namespace-scope and static-local initializers compile in both Rust models and match native C++ through nested reference uses within the full expression.`

Checks: 2 of 2 passed. Verification: no defect found.

Timeline