From patchwork Tue Oct 30 14:50:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 990891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-488609-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="msqNoDyX"; dkim-atps=neutral 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 42kvXn5VF9z9s7W for ; Wed, 31 Oct 2018 01:50:49 +1100 (AEDT) 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=EYdz45h3x2cb8LJsmAspkVrzDkrfFmpFoIIpV/Dk8bTr6GvH/3D1g aSgKyuRvNlEWBIvl6AKro0LWDsboc2D4qB+CEHX/vBQCvTAKp1az1i2s74uSbUdN JiCdzae5uE/IdK6SiUqNArz3VHrvvE9um7hlKxmcoGJFN2eD6i4ODw= 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=l0ykv52/J6sKsfmRgltjTX2TKII=; b=msqNoDyX2In3DUCEU57L jGapvhhujed3oy2u/g2uTxXgd2kJ4k5U+nvNKC1wfnAaDtD8VO9PirvdnWAikk/Z tBspv0b5vQToC04Xh+5lk6p9EK2zfU4HuXl9r672J2xuqjXDm59/AVQFr7+mDftc J7C+rqi34W2Y1yNzctIIYVk= Received: (qmail 76123 invoked by alias); 30 Oct 2018 14:50:34 -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 76102 invoked by uid 89); 30 Oct 2018 14:50:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Tue, 30 Oct 2018 14:50:32 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C67543154875; Tue, 30 Oct 2018 14:50:30 +0000 (UTC) Received: from localhost (unknown [10.33.36.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC3F161B80; Tue, 30 Oct 2018 14:50:29 +0000 (UTC) Date: Tue, 30 Oct 2018 14:50:27 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR libstdc++/87809 avoid invalid expressions in exception specifications Message-ID: <20181030145027.GA13646@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) If the allocator isn't default constructible then checking if the default constructor throws in an exception specification makes the declaration invalid. Use the type trait instead. PR libstdc++/87809 * include/bits/forward_list.h (_Fwd_list_impl::_Fwd_list_impl()): Use trait in exception-specification instead of possibly invalid expression. * include/bits/stl_bvector.h (_Bvector_impl::_Bvector_impl()): Likewise. * include/bits/stl_list.h (_List_impl::_List_impl()): Likewise. * include/bits/stl_vector.h (_Vector_impl::_Vector_impl()): Likewise. * testsuite/23_containers/forward_list/cons/87809.cc: New test. * testsuite/23_containers/list/cons/87809.cc: New test. * testsuite/23_containers/vector/bool/cons/87809.cc: New test. * testsuite/23_containers/vector/cons/87809.cc: New test. Tested powerpc64le-linux, committed to trunk. This needs to be backported to gcc-8-branch as well. commit 4d9fc3aa6ee2bc8a5589e4b9709b3ea6c00c87be Author: Jonathan Wakely Date: Tue Oct 30 14:09:04 2018 +0000 PR libstdc++/87809 avoid invalid expressions in exception specifications If the allocator isn't default constructible then checking if the default constructor throws in an exception specification makes the declaration invalid. Use the type trait instead. PR libstdc++/87809 * include/bits/forward_list.h (_Fwd_list_impl::_Fwd_list_impl()): Use trait in exception-specification instead of possibly invalid expression. * include/bits/stl_bvector.h (_Bvector_impl::_Bvector_impl()): Likewise. * include/bits/stl_list.h (_List_impl::_List_impl()): Likewise. * include/bits/stl_vector.h (_Vector_impl::_Vector_impl()): Likewise. * testsuite/23_containers/forward_list/cons/87809.cc: New test. * testsuite/23_containers/list/cons/87809.cc: New test. * testsuite/23_containers/vector/bool/cons/87809.cc: New test. * testsuite/23_containers/vector/cons/87809.cc: New test. diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index ebec3b5c818..1d01a54721b 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -293,7 +293,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Fwd_list_node_base _M_head; _Fwd_list_impl() - noexcept( noexcept(_Node_alloc_type()) ) + noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value) : _Node_alloc_type(), _M_head() { } diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 19c16839cfa..3752897272f 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -473,8 +473,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER : public _Bit_alloc_type, public _Bvector_impl_data { public: - _Bvector_impl() - _GLIBCXX_NOEXCEPT_IF( noexcept(_Bit_alloc_type()) ) + _Bvector_impl() _GLIBCXX_NOEXCEPT_IF( + is_nothrow_default_constructible<_Bit_alloc_type>::value) : _Bit_alloc_type() { } diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 3544981698c..cb8aa88d548 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -372,7 +372,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { __detail::_List_node_header _M_node; - _List_impl() _GLIBCXX_NOEXCEPT_IF( noexcept(_Node_alloc_type()) ) + _List_impl() _GLIBCXX_NOEXCEPT_IF( + is_nothrow_default_constructible<_Node_alloc_type>::value) : _Node_alloc_type() { } diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 40debd62396..05f9b7ef6c3 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -125,7 +125,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER struct _Vector_impl : public _Tp_alloc_type, public _Vector_impl_data { - _Vector_impl() _GLIBCXX_NOEXCEPT_IF( noexcept(_Tp_alloc_type()) ) + _Vector_impl() _GLIBCXX_NOEXCEPT_IF( + is_nothrow_default_constructible<_Tp_alloc_type>::value) : _Tp_alloc_type() { } diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/87809.cc new file mode 100644 index 00000000000..cde9dfff3e0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/87809.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2018 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 { target c++11 } } + +#include + +template +struct Alloc +{ + using value_type = T; + + T* allocate(unsigned n); + void deallocate(T* p, unsigned n); + + Alloc(int) { } + + template + Alloc(const Alloc&) { } +}; + +template + bool operator==(Alloc, Alloc) { return true; } +template + bool operator!=(Alloc, Alloc) { return false; } + +constexpr bool b + = std::is_default_constructible>>::value; diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/list/cons/87809.cc new file mode 100644 index 00000000000..d7c5256b62c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/87809.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2018 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 { target c++11 } } + +#include + +template +struct Alloc +{ + using value_type = T; + + T* allocate(unsigned n); + void deallocate(T* p, unsigned n); + + Alloc(int) { } + + template + Alloc(const Alloc&) { } +}; + +template + bool operator==(Alloc, Alloc) { return true; } +template + bool operator!=(Alloc, Alloc) { return false; } + +constexpr bool b + = std::is_default_constructible>>::value; diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/87809.cc new file mode 100644 index 00000000000..b697abe5658 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/87809.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2018 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 { target c++11 } } + +#include + +template +struct Alloc +{ + using value_type = T; + + T* allocate(unsigned n); + void deallocate(T* p, unsigned n); + + Alloc(int) { } + + template + Alloc(const Alloc&) { } +}; + +template + bool operator==(Alloc, Alloc) { return true; } +template + bool operator!=(Alloc, Alloc) { return false; } + +constexpr bool b + = std::is_default_constructible>>::value; diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/87809.cc new file mode 100644 index 00000000000..07199339b14 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/87809.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2018 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 { target c++11 } } + +#include + +template +struct Alloc +{ + using value_type = T; + + T* allocate(unsigned n); + void deallocate(T* p, unsigned n); + + Alloc(int) { } + + template + Alloc(const Alloc&) { } +}; + +template + bool operator==(Alloc, Alloc) { return true; } +template + bool operator!=(Alloc, Alloc) { return false; } + +constexpr bool b + = std::is_default_constructible>>::value;