Bug 62119 - dangling reference : gslice_array's copy constructor
Summary: dangling reference : gslice_array's copy constructor
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-13 07:47 UTC by Akira Takahashi
Modified: 2014-08-14 18:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Akira Takahashi 2014-08-13 07:47:36 UTC
follow code happens segmentation fault by dangling deference.

#include <iostream>
#include <valarray>
#include <numeric>

int main()
{
  std::valarray<int> v(15);
  std::iota(std::begin(v), std::end(v), 0);

  const std::size_t start = 1u;
  const std::valarray<std::size_t> lengths = {3u, 2u};
  const std::valarray<std::size_t> strides = {5u, 1u};

  // here
  std::gslice_array<int> result = v[std::gslice(start, lengths, strides)];

  result = 99;

  for (int x : v) {
    std::cout << x << std::endl;
  }
}


gslice_array.h

private:
  const valarray<size_t>& _M_index;


template<typename _Tp>
  inline
  gslice_array<_Tp>::gslice_array(const gslice_array<_Tp>& __a)
  : _M_array(__a._M_array), _M_index(__a._M_index) {}
Comment 1 Akira Takahashi 2014-08-13 07:58:45 UTC
expected output:

0
99
99
3
4
5
99
99
8
9
10
99
99
13
14