public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/63314] New: valarray mask/indices refers to temporary
@ 2014-09-19 16:41 helloworld922 at hotmail dot com
  2014-09-19 23:18 ` [Bug libstdc++/63314] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: helloworld922 at hotmail dot com @ 2014-09-19 16:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63314

            Bug ID: 63314
           Summary: valarray mask/indices refers to temporary
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: helloworld922 at hotmail dot com

std::mask_array appears to be holding a reference to the underlying _M_data of
the mask std::valarray. This is a problem when the mask valarray is a
temporary:

std::valarray<int> data = {1,4,0,2,5};
std::mask_array<int> marr = data[data <= 2];

Here, the data <= 2 mask is a temporary and sarr will have an invalid address
for for the mask _M_data. Trying to do anything with mask_array at this point
would have problems, i.e.:

marr = 11;

will be undefined behavior.

Similarly, there is an identical issue with std::indirect_array:

std::indirect_array<int> iarr = data[std::valarray<size_t>({1,2,4})];

Because the underlying _M_data has no ownership in mask_array/indirect_array,
there are additional problems when trying to return the given type:

std::mask_array<int> doit(const std::valarray<int> &data)
{
    std::valarray<size_t> idx = {1,2,3};
    return data[idx];
}

It is unclear to me if this behavior is allowed by the standard, but it
certainly looks fishy, especially given that the deduced type for this:

auto marr = data[data <= 2];

is std::mask_array


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/63314] valarray mask/indices refers to temporary
  2014-09-19 16:41 [Bug libstdc++/63314] New: valarray mask/indices refers to temporary helloworld922 at hotmail dot com
@ 2014-09-19 23:18 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2014-09-19 23:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63314

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |normal

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to helloworld922 from comment #0)
> It is unclear to me if this behavior is allowed by the standard, but it
> certainly looks fishy

In that case you really shouldn't claim the bug's severity is "blocker"


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-19 23:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-19 16:41 [Bug libstdc++/63314] New: valarray mask/indices refers to temporary helloworld922 at hotmail dot com
2014-09-19 23:18 ` [Bug libstdc++/63314] " redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).