Repository navigation
Commit da786e4
authored
Return a value from xoptional_assembly_storage::data() (#2955)
# Checklist
- [x] The title and commit message(s) are descriptive.
- [x] Small commits made to fix your PR have been squashed to avoid
history pollution.
- [x] Tests have been added for new features or bug fixes.
- [x] API of new functions and classes are documented (no public API
changes).
# Description
Both overloads of `xoptional_assembly_storage::data()` contained
`pointer(front());` without `return`. C++ parses that statement as the
declaration of a local function named `front`, so the functions fall off
the end without returning a value:
```cpp
auto stor = xt::optional_assembly_storage(v, f);
stor.data()->value(); // undefined behavior, segfaults with GCC 15 at -O2
```
Calling both overloads in the same translation unit does not compile
either, because the two local declarations of `front` have different
return types. GCC reports the statement with `-Wparentheses` and
`-Wshadow`.
`data()` now returns the closure pointer to the front element.
`xoptional_assembly_storage.data` checks the mutable and const
overloads; it does not compile on master and passes with the fix.1 parent 75abad5 commit da786e4
2 files changed
Lines changed: 20 additions & 2 deletions
File tree
- include/xtensor/optional
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
| 323 | + | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
| 329 | + | |
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
87 | 105 | | |
88 | 106 | | |
89 | 107 | | |
| |||
0 commit comments