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: 78942 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2549493qge; Mon, 24 Oct 2016 05:26:06 -0700 (PDT) X-Received: by 10.98.93.83 with SMTP id r80mr28061943pfb.17.1477311966019; Mon, 24 Oct 2016 05:26:06 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j128si15158012pgc.174.2016.10.24.05.26.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 05:26:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439387-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439387-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439387-patch=linaro.org@gcc.gnu.org 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=ZToINmb0XKC2Oy/0GCMwUPTf3t4gkSKHIDLfcDgnd+CrddpZyUu5s Ij0slqzASqO2ZQ6/tNE6Hc+I7Z+sbTq3r42bDw4pMJmVSgrxEASxS3LOafqRA1oY 8SDjEUcdI+D9wweuiC66OJ5ULf+gU3hR5rbQmLW+2tSPI8ybQW4hgk= 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=Pl64OJecCWgZ+zc/j0W7 lrJ0DER4Cm1LspO1icD5iZM4FSu2wUwO6nT+x526h4PidVwfOC3jVjm5P9k9VdyM ShJfrH1JCvfUPZLsVTDZ5KQAxZ9pqDR3FpFRU4utPhKB/7LWHIX9MmFgBGmR9DIt mbxbVqL4wkiOjB8ZvZ8+Mo8= 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 };