Skip to content

Return a value from xoptional_assembly_storage::data() - #2955

Open
gouarin wants to merge 1 commit into
xtensor-stack:masterfrom
gouarin:fix-optional-storage-data
Open

gouarin wants to merge 1 commit into
xtensor-stack:masterfrom
gouarin:fix-optional-storage-data

Conversation

@gouarin

@gouarin gouarin commented Oct 29, 2026

Copy link
Copy Markdown
Member

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • 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:

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.

Both data() overloads had the statement pointer(front()); with no
return. C++ parses that line as the declaration of a local function
named front, which is what GCC's -Wparentheses and -Wshadow pointed
at. Each overload then fell off the end of a function returning a
value:

- calling one overload is undefined behavior. With GCC 15 at -O2,
  stor.data()->value() segfaults.
- calling both in one translation unit does not compile, because the
  two local declarations of xt::front have different return types.

Return the closure pointer to the front element, and add a test for
the mutable and const overloads.
@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ Unable to measure the execution of 1 benchmark

This benchmark measured no execution time, so its result is not comparable and counts as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

✅ 255 untouched benchmarks


Comparing gouarin:fix-optional-storage-data (a938086) with master (57f3d07)

Open in CodSpeed

This branch has not been deployed

No deployments
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.

1 participant