From patchwork Mon Oct 24 12:25:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 685798 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t2b9N6cfQz9svs for ; Mon, 24 Oct 2016 23:26:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=H0czs6W3; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=YSy96nXepoXMjH/R2FnHy8FSNCatf7hN+rhJ59qOqsPefPA5jy+i+ MW/JK6mc5Iiin/JV1h8/zYK3aV75RZV5WSqcUHk468O0uYPsdXv2iiadN9usLkX2 swl/5YqHJ3wXHgj08R7nPQ9YhczzXkh7nZGNpXXQMEDRvofl62IsMY= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=qRXL8YG7wmF3JhNtKrAWvg7mINo=; b=H0czs6W3tRNft15wfjRL jF9pNeaMT8BYdL5Hq/t03Cou74p7JDbiV6nNcGGiNsqvO5XE1NMYB/pOozXUi/nn 07hUIU37QjoNFX15U+ZFqG0ZM9XPSD7uINEXUjhVq3DenWSoJXWE+SGI8S8RNL8g bQzO1grzUATnRMhwX5rQH1E= Received: (qmail 72639 invoked by alias); 24 Oct 2016 12:25:44 -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 72595 invoked by uid 89); 24 Oct 2016 12:25:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=*__ptr, silent, Hx-languages-length:2474 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Oct 2016 12:25:33 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 486983D971; Mon, 24 Oct 2016 12:25:32 +0000 (UTC) Received: from localhost (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9OCPV20024446; Mon, 24 Oct 2016 08:25:31 -0400 Date: Mon, 24 Oct 2016 13:25:31 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Make vector::data() return type consistent in C++98 Message-ID: <20161024122531.GK2922@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) At https://gcc.gnu.org/ml/libstdc++/2016-08/msg00123.html I suggested changing the non-standard return type of vector::data() in C++98 mode. Nobody objected, so I'm making that change. This removes a silent ABI incompatibility betwen C++98 mode and later modes, for std::vector::data() where A::pointer is not T*. For most uses (where A is std::allocator, or A::pointer is T*) it makes no difference. * include/bits/stl_vector.h (vector::_M_data_ptr, vector::data): Change return type of non-standard C++98 extension to match C++11. Tested powerpc64le-linux, with -std=gnu++98 too, committed to trunk. commit 5ff5b46535193b9732130ba20030647e1fbb7d35 Author: Jonathan Wakely Date: Sat Oct 22 12:49:11 2016 +0100 Make vector::data() return type consistent in C++98 * include/bits/stl_vector.h (vector::_M_data_ptr, vector::data): Change return type of non-standard C++98 extension to match C++11. diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index efc569b..697a73c 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -914,19 +914,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a pointer such that [data(), data() + size()) is a valid * range. For a non-empty %vector, data() == &front(). */ -#if __cplusplus >= 201103L _Tp* -#else - pointer -#endif data() _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } -#if __cplusplus >= 201103L const _Tp* -#else - const_pointer -#endif data() const _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } @@ -1558,21 +1550,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } #endif -#if __cplusplus >= 201103L template _Up* - _M_data_ptr(_Up* __ptr) const + _M_data_ptr(_Up* __ptr) const _GLIBCXX_NOEXCEPT { return __ptr; } +#if __cplusplus >= 201103L template typename std::pointer_traits<_Ptr>::element_type* _M_data_ptr(_Ptr __ptr) const { return empty() ? nullptr : std::__addressof(*__ptr); } #else - template - _Ptr - _M_data_ptr(_Ptr __ptr) const + template + _Up* + _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT { return __ptr; } + + template + value_type* + _M_data_ptr(_Ptr __ptr) + { return __ptr.operator->(); } + + template + const value_type* + _M_data_ptr(_Ptr __ptr) const + { return __ptr.operator->(); } #endif };