Fix dangling reference in IndexedView with expression indices

Summary

  • Fix use-after-free when Eigen expression types (Reshaped, Block, CwiseOp, etc.) are used as index arguments to operator()
  • IndexedView stored expression objects by value, but these may hold internal references to temporaries destroyed at end of expression
  • Add IndexedViewHelperIndicesWrapper specialization that evaluates expression indices to plain objects before storing

Reproducer (from #1943 (closed))

auto view = values(all, Array<int,1,1>{0}.reshaped());  // was segfault

Test plan

  • Added regression tests for reshaped, block, CwiseOp, and reverse expression indices
  • Verified plain ArrayXi and std::vector indices still work without copies
  • All existing indexed_view and array_cwise tests pass
  • ASan clean (no stack-use-after-return)

Closes #1943 (closed)

Merge request reports

Loading