From patchwork Thu Jan 7 15:01:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 564337 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 605AC14017E for ; Fri, 8 Jan 2016 02:02:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=gBrt2kEB; 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=FqFfxCiXCsWrqJgLL5jowO1Fg/jsk02YFv14rA3yAQrfh6R1sEr33 JR6Axgw+J619Va1VbNcg0xgkbsET5LPb5s/SScy7i/mDb1Bq6z/HNGrWfVWq+uB4 HSz1joFyhiMKvzPHXtlJPBCLAB+A2K39cBXb3rbsDArU0zTSHIZ6A8= 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=cUdoszymgyEvGdptPEpkvX554SM=; b=gBrt2kEBznYRcTG/ZkpQ 2IM6cOvpLPhvbTNEnUR5SzOSZn+MHMnwnnwMePlqIJIOrpOy3CAT74XNiFwPllNc Up3IlXOpn452rhJL/MU7/tg1MMlZyK/pDBGhx11ebSyK1XQZIsppsk86nrk1wQw/ I1mkxU28jKMC+a3hnBDyb0Y= Received: (qmail 101313 invoked by alias); 7 Jan 2016 15:01:51 -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 100453 invoked by uid 89); 7 Jan 2016 15:01:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=__i, 618, 507, 1, 49 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 07 Jan 2016 15:01:42 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id D2664C0A8486; Thu, 7 Jan 2016 15:01:40 +0000 (UTC) Received: from localhost (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u07F1dfU019557; Thu, 7 Jan 2016 10:01:40 -0500 Date: Thu, 7 Jan 2016 15:01:39 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] libstdc++/69105, 69106, 69114 use std::addressof Message-ID: <20160107150139.GC30323@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.5.24 (2015-08-30) A bumper crop of addressof bugs where I was using & but should have used std::addressof. Tested powerpc64le-linux, committed to trunk. commit 883339d9559e774b2e34ad32b04db92f7dfb4b0b Author: Jonathan Wakely Date: Thu Jan 7 14:31:15 2016 +0000 Use std::addressof in insert iterators, allocators and promises PR libstdc++/69105 PR libstdc++/69106 PR libstdc++/69114 * include/bits/stl_iterator.h (back_insert_iterator, front_insert_iterator, insert_iterator): Use __addressof (LWG 2324). * include/bits/uses_allocator.h (__use_alloc): Use __addressof. * include/std/future (__future::base::_State_baseV2::__setter): Likewise. * include/std/scoped_allocator (__outermost): Likewise. * testsuite/20_util/scoped_allocator/69114.cc: New. * testsuite/20_util/uses_allocator/69114.cc: New. * testsuite/30_threads/promise/69106.cc: New. diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index c86bec3..3401cd0 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -451,7 +451,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// The only way to create this %iterator is with a container. explicit - back_insert_iterator(_Container& __x) : container(&__x) { } + back_insert_iterator(_Container& __x) + : container(std::__addressof(__x)) { } /** * @param __value An instance of whatever type @@ -541,7 +542,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef _Container container_type; /// The only way to create this %iterator is with a container. - explicit front_insert_iterator(_Container& __x) : container(&__x) { } + explicit front_insert_iterator(_Container& __x) + : container(std::__addressof(__x)) { } /** * @param __value An instance of whatever type @@ -640,7 +642,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * initial position (a normal %iterator into the container). */ insert_iterator(_Container& __x, typename _Container::iterator __i) - : container(&__x), iter(__i) {} + : container(std::__addressof(__x)), iter(__i) {} /** * @param __value An instance of whatever type diff --git a/libstdc++-v3/include/bits/uses_allocator.h b/libstdc++-v3/include/bits/uses_allocator.h index 660a64e..b3c3f60 100644 --- a/libstdc++-v3/include/bits/uses_allocator.h +++ b/libstdc++-v3/include/bits/uses_allocator.h @@ -99,7 +99,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __use_alloc(const _Alloc& __a) { __uses_alloc_t<_Tp, _Alloc, _Args...> __ret; - __ret._M_a = &__a; + __ret._M_a = std::__addressof(__a); return __ret; } diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index d2ac68b..80b7b06 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -507,7 +507,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static _Setter<_Res, _Arg&&> __setter(promise<_Res>* __prom, _Arg&& __arg) { - return _Setter<_Res, _Arg&&>{ __prom, &__arg }; + return _Setter<_Res, _Arg&&>{ __prom, std::__addressof(__arg) }; } template diff --git a/libstdc++-v3/include/std/scoped_allocator b/libstdc++-v3/include/std/scoped_allocator index c30ec7c..aac2dfe 100644 --- a/libstdc++-v3/include/std/scoped_allocator +++ b/libstdc++-v3/include/std/scoped_allocator @@ -50,7 +50,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline auto - __do_outermost(_Alloc& __a, _Alloc*) -> decltype(__a.outer_allocator()) + __do_outermost(_Alloc& __a, int) -> decltype(__a.outer_allocator()) { return __a.outer_allocator(); } template @@ -61,8 +61,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO: make recursive (see note in 20.12.4/1) template inline auto - __outermost(_Alloc& __a) -> decltype(__do_outermost(__a, &__a)) - { return __do_outermost(__a, &__a); } + __outermost(_Alloc& __a) + -> decltype(__do_outermost(__a, 0)) + { return __do_outermost(__a, 0); } template class scoped_allocator_adaptor; diff --git a/libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc b/libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc new file mode 100644 index 0000000..6890d18 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2016 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-do compile } +// { dg-options "-std=gnu++11" } + +// PR libstdc++/69114 + +#include + +template +struct Alloc +{ + using value_type = T; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + T* allocate(std::size_t); + void deallocate(T*, std::size_t); + + bool operator==(const Alloc&) const { return true; } + bool operator!=(const Alloc&) const { return false; } + + void operator&() = delete; +}; + +void +test01() +{ + using alloc_type = Alloc>; + std::scoped_allocator_adaptor a; + a.construct(a.allocate(1)); +} diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc new file mode 100644 index 0000000..0ab7ed3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2016 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-do compile } +// { dg-options "-std=gnu++11" } + +// PR libstdc++/69114 + +#include + +template +struct Alloc +{ + using value_type = T; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + T* allocate(std::size_t); + void deallocate(T*, std::size_t); + + bool operator==(const Alloc&) const { return true; } + bool operator!=(const Alloc&) const { return false; } + + void operator&() = delete; +}; + +void +test01() +{ + Alloc a; + std::tuple t(std::allocator_arg, a); +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/69106.cc b/libstdc++-v3/testsuite/30_threads/promise/69106.cc new file mode 100644 index 0000000..921ded1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/69106.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2016 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-do compile } +// { dg-options "-std=gnu++11" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +#include + +struct foo { + void operator&() const = delete; +}; + +void test01() +{ + std::promise p; + p.set_value(foo()); +}