From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24970 invoked by alias); 19 Sep 2014 16:41:50 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24913 invoked by uid 48); 19 Sep 2014 16:41:38 -0000 From: "helloworld922 at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/63314] New: valarray mask/indices refers to temporary Date: Fri, 19 Sep 2014 16:41:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 4.8.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: blocker X-Bugzilla-Who: helloworld922 at hotmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-09/txt/msg01973.txt.bz2 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 data = {1,4,0,2,5}; std::mask_array 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 iarr = data[std::valarray({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 doit(const std::valarray &data) { std::valarray 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