Skip to content

[embind] Add static_assert against return_value_policy::reference() on by-value returns - #28514

Merged
juj merged 1 commit into
emscripten-core:mainfrom
juj:embind_rvp_reference_static_assert
Dec 2, 2026
Merged

juj merged 1 commit into
emscripten-core:mainfrom
juj:embind_rvp_reference_static_assert

Conversation

@juj

@juj juj commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Binding a function, method or property getter that returns a bound class by value with return_value_policy::reference() compiled without complaint and returned the address of a destroyed temporary to JS. Reject this at compile time instead.

GenericBindingType::toWireType() takes the returned value as a forwarding reference, so it sees an lvalue reference for the supported cases (T& returns and member object properties) and a non-reference type when it was handed a temporary.

Followup to #28507.

@juj
juj requested a review from brendandahl as a code owner December 2, 2026 00:37
@juj
juj enabled auto-merge (squash) December 2, 2026 10:00
…n by-value returns

Binding a function, method or property getter that returns a bound class
by value with return_value_policy::reference() compiled without complaint
and returned the address of a destroyed temporary to JS. Reject this at
compile time instead.

GenericBindingType::toWireType() takes the returned value as a forwarding
reference, so it sees an lvalue reference for the supported cases (T&
returns and member object properties) and a non-reference type when it was
handed a temporary.

Followup to emscripten-core#28507.
@juj
juj force-pushed the embind_rvp_reference_static_assert branch from b8cdefd to 12ac3ab Compare December 2, 2026 10:03
@juj
juj merged commit 21854e5 into emscripten-core:main Dec 2, 2026
42 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants