Skip to content

🚸 Add lifetime annotation to write_spec[]#140

Merged
elbeno merged 1 commit into
intel:mainfrom
elbeno:add-lifetime-annotation
Feb 5, 2026
Merged

🚸 Add lifetime annotation to write_spec[]#140
elbeno merged 1 commit into
intel:mainfrom
elbeno:add-lifetime-annotation

Conversation

@elbeno

@elbeno elbeno commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Problem:

  • operator[] on a (non-const) write_spec returns a field_proxy so that assignment works. This means that code like this is a pitfall:
auto result = sync_read(group / "reg.field_f"); // missing const
return result["reg.field"_f];                   // operator[] called on non-const

This code returns a field_proxy which is a view type referencing the result. Which dangles after the return.

Solution:

  • Add lifetimebound annotation to operator[] so that clang's -Wreturn-stack-address fires in this case.

Problem:
- `operator[]` on a (non-`const`) `write_spec` returns a `field_proxy` so that
  assignment works. This means that code like this is a pitfall:

```cpp
auto result = sync_read(group / "reg.field_f"); // missing const
return result["reg.field"_f];                   // operator[] called on non-const
```

This code returns a `field_proxy` which is a view type referencing the result.
Which dangles after the `return`.

Solution:
- Add lifetimebound annotation to `operator[]` so that clang's
  `-Wreturn-stack-address` fires in this case.
@elbeno
elbeno merged commit bfc5b64 into intel:main Feb 5, 2026
31 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