From patchwork Mon Apr 22 10:08:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 238396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 68E3E2C05AF for ; Mon, 22 Apr 2013 20:09:04 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=xwIIiQ588SQ2y3lgQ08vTYRUR8SS+Bf9MjvVpKEgeDb rTDjTMVpTwLcKDhmBZfveJ9yEieQ6kW79xdXXcwKkF5LjBEH5rkmaHXrup619398 kxK2+aB+G/BjEZN7y/SMqQKcErxc5GjP3MK44YDAEj1kNuxMIpmoKZ7Sa5D/2cJ0 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=cYaFVc0ZzwW5Oc/fxJy9VzOjyCc=; b=o2q0UrHCyVHqcFHaL RTtaoqWrh9Eovfudt687SSgo9pPf8qUeWQ2hGA+/DdWoDtFrrOrsQSMR0d3dz4yy aCk8GJ+LEfmwtr9+1JQ+Wz6Jg6mhIY5SHiMYLhgO6NoAIoAz+EdSPBtyMKKxc6vH /1Wg/Ky6EU9PdJ4+RdmcnxEZRc= Received: (qmail 2080 invoked by alias); 22 Apr 2013 10:08:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2063 invoked by uid 89); 22 Apr 2013 10:08:56 -0000 X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 22 Apr 2013 10:08:54 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r3MA8p1q020021 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Apr 2013 10:08:52 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3MA8ooO008831 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 22 Apr 2013 10:08:51 GMT Received: from abhmt107.oracle.com (abhmt107.oracle.com [141.146.116.59]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3MA8otB005638; Mon, 22 Apr 2013 10:08:50 GMT Received: from poldo4.casa (/79.52.233.36) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Apr 2013 03:08:49 -0700 Message-ID: <51750C2F.1060908@oracle.com> Date: Mon, 22 Apr 2013 12:08:47 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/57010 X-Virus-Found: No Hi, a straightforward issue, tested x86_64-linux, committed mainline and 4_8-branch. Thanks, Paolo. //////////////////////// 2013-04-22 Paolo Carlini PR libstdc++/57010 * include/bits/stl_heap.h (pop_heap): Avoid self move-assignment. * testsuite/25_algorithms/pop_heap/57010.cc: New. Index: include/bits/stl_heap.h =================================================================== --- include/bits/stl_heap.h (revision 198124) +++ include/bits/stl_heap.h (working copy) @@ -291,8 +291,11 @@ __glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_heap(__first, __last); - --__last; - std::__pop_heap(__first, __last, __last); + if (__last - __first > 1) + { + --__last; + std::__pop_heap(__first, __last, __last); + } } template 1) + { + --__last; + std::__pop_heap(__first, __last, __last, __comp); + } } /** Index: testsuite/25_algorithms/pop_heap/57010.cc =================================================================== --- testsuite/25_algorithms/pop_heap/57010.cc (revision 0) +++ testsuite/25_algorithms/pop_heap/57010.cc (working copy) @@ -0,0 +1,55 @@ +// Copyright (C) 2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++11" } + +#include +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container container; + +void test01() +{ + { + rvalstruct makeheap[1]; + container makecon(makeheap, makeheap + 1); + + std::push_heap(makecon.begin(), makecon.end()); + std::pop_heap(makecon.begin(), makecon.end()); + } + + { + rvalstruct makeheap[1]; + container makecon(makeheap, makeheap + 1); + + std::push_heap(makecon.begin(), makecon.end(), std::less()); + std::pop_heap(makecon.begin(), makecon.end(), std::less()); + } +} + +int main() +{ + test01(); + return 0; +}