From patchwork Tue Nov 6 18:19:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 197530 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]) by ozlabs.org (Postfix) with SMTP id D83F62C009B for ; Wed, 7 Nov 2012 05:20:24 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352830825; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=agduMr9wGd1QHFcDZ0822A6zt3s=; b=sNIgMpo2gxaqJt9 xFvSNOX3GlHcDMeGbP9jDKoazuSdn5ZxsYlUCA0I56YuI5oMSCoviDfuPlf9ToO0 Nqhnl0jxza3/DPi/JGGQAiYFoWp1+lzDv2qW0ehdenJAR3hLzUTE5+qxDQdfLZWy +AnqYcch47KoLR5ERaIRzCbRww1I= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=agdw8rqj4Gixaww2/70mD4UU7t9p0DeZDjGF4r1Qb2HkhOe8+/DvDDdJRlVZHT yAfEBn8Q3u6UoEluReDhSMboUvlyxtZ/skcEniYqOOwUQ52qi8hlRyyMShHfffVT ie3EuQeyuMGAP87iEwMkQUX8IdHzpTahpcRuO/IXxEy+M=; Received: (qmail 6503 invoked by alias); 6 Nov 2012 18:20:02 -0000 Received: (qmail 6459 invoked by uid 22791); 6 Nov 2012 18:20:00 -0000 X-SWARE-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL, BAYES_00, FSL_NEW_HELO_USER, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 06 Nov 2012 18:19:46 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qA6IJi6x013189 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 6 Nov 2012 18:19:45 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qA6IJiKF022998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 6 Nov 2012 18:19:44 GMT Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id qA6IJiDF007192; Tue, 6 Nov 2012 12:19:44 -0600 Received: from [192.168.1.4] (/79.40.56.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Nov 2012 10:19:43 -0800 Message-ID: <509954BD.60500@oracle.com> Date: Tue, 06 Nov 2012 19:19:41 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121025 Thunderbird/16.0.2 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/51850 X-IsSubscribed: yes 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 Hi, this is what I'm finishing testing to add a debug-mode std::array. Things work pretty well, but I'm not fiddling for now with the iterators: std::array must remain an aggregate, thus we can't have base classes, thus we can't really use the standard debug-mode infrastructure for those. Basing on the various email exchanges over the last years, I understand people will like anyway having operator[], and also front and back checked (consistently with, eg, std::vector). In any case the rest in enhancement beyond the PR. Thanks, Paolo. //////////////////////// 2012-11-06 Paolo Carlini PR libstdc++/51850 * include/debug/array: New, debug-mode implementation. * include/profile/array: New. * include/std/array: Adjust. * include/std/tuple: Just include . * include/Makefile.am: Add. * include/Makefile.in: Regenerate. * testsuite/23_containers/array/debug/front1_neg.cc: New. * testsuite/23_containers/array/debug/ square_brackets_operator1_neg.cc: Likewise. * testsuite/23_containers/array/debug/front2_neg.cc: Likewise. * testsuite/23_containers/array/debug/ square_brackets_operator2_neg.cc: Likewise. * testsuite/23_containers/array/debug/back1_neg.cc: Likewise. * testsuite/23_containers/array/debug/back2_neg.cc: Likewise. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Tweak to run only in normal-mode. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Likewise. * testsuite/23_containers/array/tuple_interface/get_debug_neg.cc: New. * testsuite/23_containers/array/tuple_interface/ tuple_element_debug_neg.cc: Likewise. Index: include/debug/array =================================================================== --- include/debug/array (revision 0) +++ include/debug/array (working copy) @@ -0,0 +1,321 @@ +// Debugging array implementation -*- C++ -*- + +// Copyright (C) 2012 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file debug/array + * This is a Standard C++ Library header. + */ + +#ifndef _GLIBCXX_DEBUG_ARRAY +#define _GLIBCXX_DEBUG_ARRAY 1 + +#pragma GCC system_header + +#include + +#ifndef _GLIBCXX_THROW_OR_ABORT +# if __EXCEPTIONS +# define _GLIBCXX_THROW_OR_ABORT(_Exc) (throw (_Exc)) +# else +# define _GLIBCXX_THROW_OR_ABORT(_Exc) (__builtin_abort()) +# endif +#endif + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace __debug +{ + template + struct array + { + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + // Support for zero-sized arrays mandatory. + typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type; + typename _AT_Type::_Type _M_elems; + + template + struct _Array_check_subscript + { + std::size_t size() { return _Size; } + + _Array_check_subscript(std::size_t __index) + { __glibcxx_check_subscript(__index); } + }; + + template + struct _Array_check_nonempty + { + bool empty() { return _Size == 0; } + + _Array_check_nonempty() + { __glibcxx_check_nonempty(); } + }; + + // No explicit construct/copy/destroy for aggregate type. + + // DR 776. + void + fill(const value_type& __u) + { std::fill_n(begin(), size(), __u); } + + void + swap(array& __other) + noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))) + { std::swap_ranges(begin(), end(), __other.begin()); } + + // Iterators. + iterator + begin() noexcept + { return iterator(data()); } + + const_iterator + begin() const noexcept + { return const_iterator(data()); } + + iterator + end() noexcept + { return iterator(data() + _Nm); } + + const_iterator + end() const noexcept + { return const_iterator(data() + _Nm); } + + reverse_iterator + rbegin() noexcept + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const noexcept + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() noexcept + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const noexcept + { return const_reverse_iterator(begin()); } + + const_iterator + cbegin() const noexcept + { return const_iterator(data()); } + + const_iterator + cend() const noexcept + { return const_iterator(data() + _Nm); } + + const_reverse_iterator + crbegin() const noexcept + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const noexcept + { return const_reverse_iterator(begin()); } + + // Capacity. + constexpr size_type + size() const noexcept { return _Nm; } + + constexpr size_type + max_size() const noexcept { return _Nm; } + + constexpr bool + empty() const noexcept { return size() == 0; } + + // Element access. + reference + operator[](size_type __n) + { + __glibcxx_check_subscript(__n); + return _AT_Type::_S_ref(_M_elems, __n); + } + + constexpr const_reference + operator[](size_type __n) const noexcept + { + return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n) + : (_GLIBCXX_THROW_OR_ABORT (_Array_check_subscript<_Nm>(__n)), + _AT_Type::_S_ref(_M_elems, 0)); + } + + reference + at(size_type __n) + { + if (__n >= _Nm) + std::__throw_out_of_range(__N("array::at")); + return _AT_Type::_S_ref(_M_elems, __n); + } + + constexpr const_reference + at(size_type __n) const + { + // Result of conditional expression must be an lvalue so use + // boolean ? lvalue : (throw-expr, lvalue) + return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n) + : (std::__throw_out_of_range(__N("array::at")), + _AT_Type::_S_ref(_M_elems, 0)); + } + + reference + front() + { + __glibcxx_check_nonempty(); + return *begin(); + } + + constexpr const_reference + front() const + { + return _Nm ? _AT_Type::_S_ref(_M_elems, 0) + : (_GLIBCXX_THROW_OR_ABORT (_Array_check_nonempty<_Nm>()), + _AT_Type::_S_ref(_M_elems, 0)); + } + + reference + back() + { + __glibcxx_check_nonempty(); + return _Nm ? *(end() - 1) : *end(); + } + + constexpr const_reference + back() const + { + return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1) + : (_GLIBCXX_THROW_OR_ABORT (_Array_check_nonempty<_Nm>()), + _AT_Type::_S_ref(_M_elems, 0)); + } + + pointer + data() noexcept + { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); } + + const_pointer + data() const noexcept + { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); } + }; + + // Array comparisons. + template + inline bool + operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return std::equal(__one.begin(), __one.end(), __two.begin()); } + + template + inline bool + operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one == __two); } + + template + inline bool + operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) + { + return std::lexicographical_compare(__a.begin(), __a.end(), + __b.begin(), __b.end()); + } + + template + inline bool + operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return __two < __one; } + + template + inline bool + operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one > __two); } + + template + inline bool + operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one < __two); } + + // Specialized algorithms. + template + inline void + swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) + noexcept(noexcept(__one.swap(__two))) + { __one.swap(__two); } + + template + constexpr _Tp& + get(array<_Tp, _Nm>& __arr) noexcept + { + static_assert(_Int < _Nm, "index is out of bounds"); + return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>:: + _S_ref(__arr._M_elems, _Int); + } + + template + constexpr _Tp&& + get(array<_Tp, _Nm>&& __arr) noexcept + { + static_assert(_Int < _Nm, "index is out of bounds"); + return std::move(get<_Int>(__arr)); + } + + template + constexpr const _Tp& + get(const array<_Tp, _Nm>& __arr) noexcept + { + static_assert(_Int < _Nm, "index is out of bounds"); + return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>:: + _S_ref(__arr._M_elems, _Int); + } +} // namespace __debug + + // Tuple interface to class template array. + + /// tuple_size + template + class tuple_size; + + template + struct tuple_size<__debug::array<_Tp, _Nm>> + : public integral_constant { }; + + /// tuple_element + template + class tuple_element; + + template + struct tuple_element<_Int, __debug::array<_Tp, _Nm>> + { + static_assert(_Int < _Nm, "index is out of bounds"); + typedef _Tp type; + }; +} // namespace std + +#undef _GLIBCXX_THROW_OR_ABORT + +#endif // _GLIBCXX_DEBUG_ARRAY Index: include/std/tuple =================================================================== --- include/std/tuple (revision 193210) +++ include/std/tuple (working copy) @@ -1,7 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 -// Free Software Foundation, Inc. +// Copyright (C) 2007-2012 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 @@ -37,6 +36,7 @@ #else #include +#include #include namespace std _GLIBCXX_VISIBILITY(default) @@ -862,18 +862,6 @@ forward_as_tuple(_Elements&&... __args) noexcept { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); } - - template struct array; - - template - constexpr _Tp& get(array<_Tp, _Nm>&) noexcept; - - template - constexpr _Tp&& get(array<_Tp, _Nm>&&) noexcept; - - template - constexpr const _Tp& get(const array<_Tp, _Nm>&) noexcept; - template struct __is_tuple_like_impl : false_type { }; Index: include/std/array =================================================================== --- include/std/array (revision 193210) +++ include/std/array (working copy) @@ -41,7 +41,7 @@ namespace std _GLIBCXX_VISIBILITY(default) { -_GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_BEGIN_NAMESPACE_CONTAINER template struct __array_traits @@ -93,8 +93,8 @@ typedef std::reverse_iterator const_reverse_iterator; // Support for zero-sized arrays mandatory. - typedef std::__array_traits<_Tp, _Nm> _AT_Type; - typename _AT_Type::_Type _M_elems; + typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type; + typename _AT_Type::_Type _M_elems; // No explicit construct/copy/destroy for aggregate type. @@ -210,7 +210,7 @@ back() const { return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1) - : _AT_Type::_S_ref(_M_elems, _Nm); + : _AT_Type::_S_ref(_M_elems, 0); } pointer @@ -289,7 +289,8 @@ get(array<_Tp, _Nm>& __arr) noexcept { static_assert(_Int < _Nm, "index is out of bounds"); - return std::__array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int); + return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>:: + _S_ref(__arr._M_elems, _Int); } template @@ -305,12 +306,21 @@ get(const array<_Tp, _Nm>& __arr) noexcept { static_assert(_Int < _Nm, "index is out of bounds"); - return std::__array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int); + return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>:: + _S_ref(__arr._M_elems, _Int); } -_GLIBCXX_END_NAMESPACE_VERSION -} // namespace +_GLIBCXX_END_NAMESPACE_CONTAINER +} // namespace std +#ifdef _GLIBCXX_DEBUG +# include +#endif + +#ifdef _GLIBCXX_PROFILE +# include +#endif + #endif // __GXX_EXPERIMENTAL_CXX0X__ #endif // _GLIBCXX_ARRAY Index: include/profile/array =================================================================== --- include/profile/array (revision 0) +++ include/profile/array (working copy) @@ -0,0 +1,273 @@ +// Profile array implementation -*- C++ -*- + +// Copyright (C) 2012 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/array + * This is a Standard C++ Library header. + */ + +#ifndef _GLIBCXX_PROFILE_ARRAY +#define _GLIBCXX_PROFILE_ARRAY 1 + +#pragma GCC system_header + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace __profile +{ + template + struct array + { + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + // Support for zero-sized arrays mandatory. + typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type; + typename _AT_Type::_Type _M_elems; + + // No explicit construct/copy/destroy for aggregate type. + + // DR 776. + void + fill(const value_type& __u) + { std::fill_n(begin(), size(), __u); } + + void + swap(array& __other) + noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))) + { std::swap_ranges(begin(), end(), __other.begin()); } + + // Iterators. + iterator + begin() noexcept + { return iterator(data()); } + + const_iterator + begin() const noexcept + { return const_iterator(data()); } + + iterator + end() noexcept + { return iterator(data() + _Nm); } + + const_iterator + end() const noexcept + { return const_iterator(data() + _Nm); } + + reverse_iterator + rbegin() noexcept + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const noexcept + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() noexcept + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const noexcept + { return const_reverse_iterator(begin()); } + + const_iterator + cbegin() const noexcept + { return const_iterator(data()); } + + const_iterator + cend() const noexcept + { return const_iterator(data() + _Nm); } + + const_reverse_iterator + crbegin() const noexcept + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const noexcept + { return const_reverse_iterator(begin()); } + + // Capacity. + constexpr size_type + size() const noexcept { return _Nm; } + + constexpr size_type + max_size() const noexcept { return _Nm; } + + constexpr bool + empty() const noexcept { return size() == 0; } + + // Element access. + reference + operator[](size_type __n) + { return _AT_Type::_S_ref(_M_elems, __n); } + + constexpr const_reference + operator[](size_type __n) const noexcept + { return _AT_Type::_S_ref(_M_elems, __n); } + + reference + at(size_type __n) + { + if (__n >= _Nm) + std::__throw_out_of_range(__N("array::at")); + return _AT_Type::_S_ref(_M_elems, __n); + } + + constexpr const_reference + at(size_type __n) const + { + // Result of conditional expression must be an lvalue so use + // boolean ? lvalue : (throw-expr, lvalue) + return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n) + : (std::__throw_out_of_range(__N("array::at")), + _AT_Type::_S_ref(_M_elems, 0)); + } + + reference + front() + { return *begin(); } + + constexpr const_reference + front() const + { return _AT_Type::_S_ref(_M_elems, 0); } + + reference + back() + { return _Nm ? *(end() - 1) : *end(); } + + constexpr const_reference + back() const + { + return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1) + : _AT_Type::_S_ref(_M_elems, 0); + } + + pointer + data() noexcept + { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); } + + const_pointer + data() const noexcept + { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); } + }; + + // Array comparisons. + template + inline bool + operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return std::equal(__one.begin(), __one.end(), __two.begin()); } + + template + inline bool + operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one == __two); } + + template + inline bool + operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) + { + return std::lexicographical_compare(__a.begin(), __a.end(), + __b.begin(), __b.end()); + } + + template + inline bool + operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return __two < __one; } + + template + inline bool + operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one > __two); } + + template + inline bool + operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one < __two); } + + // Specialized algorithms. + template + inline void + swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) + noexcept(noexcept(__one.swap(__two))) + { __one.swap(__two); } + + template + constexpr _Tp& + get(array<_Tp, _Nm>& __arr) noexcept + { + static_assert(_Int < _Nm, "index is out of bounds"); + return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>:: + _S_ref(__arr._M_elems, _Int); + } + + template + constexpr _Tp&& + get(array<_Tp, _Nm>&& __arr) noexcept + { + static_assert(_Int < _Nm, "index is out of bounds"); + return std::move(get<_Int>(__arr)); + } + + template + constexpr const _Tp& + get(const array<_Tp, _Nm>& __arr) noexcept + { + static_assert(_Int < _Nm, "index is out of bounds"); + return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>:: + _S_ref(__arr._M_elems, _Int); + } +} // namespace __profile + + // Tuple interface to class template array. + + /// tuple_size + template + class tuple_size; + + template + struct tuple_size<__profile::array<_Tp, _Nm>> + : public integral_constant { }; + + /// tuple_element + template + class tuple_element; + + template + struct tuple_element<_Int, __profile::array<_Tp, _Nm>> + { + static_assert(_Int < _Nm, "index is out of bounds"); + typedef _Tp type; + }; +} // namespace std + +#endif // _GLIBCXX_PROFILE_ARRAY Index: include/Makefile.am =================================================================== --- include/Makefile.am (revision 193210) +++ include/Makefile.am (working copy) @@ -705,6 +705,7 @@ debug_srcdir = ${glibcxx_srcdir}/include/debug debug_builddir = ./debug debug_headers = \ + ${debug_srcdir}/array \ ${debug_srcdir}/bitset \ ${debug_srcdir}/debug.h \ ${debug_srcdir}/deque \ @@ -786,6 +787,7 @@ profile_srcdir = ${glibcxx_srcdir}/include/profile profile_builddir = ./profile profile_headers = \ + ${profile_srcdir}/array \ ${profile_srcdir}/base.h \ ${profile_srcdir}/unordered_map \ ${profile_srcdir}/unordered_set \ Index: include/Makefile.in =================================================================== --- include/Makefile.in (revision 193210) +++ include/Makefile.in (working copy) @@ -958,6 +958,7 @@ debug_srcdir = ${glibcxx_srcdir}/include/debug debug_builddir = ./debug debug_headers = \ + ${debug_srcdir}/array \ ${debug_srcdir}/bitset \ ${debug_srcdir}/debug.h \ ${debug_srcdir}/deque \ @@ -1041,6 +1042,7 @@ profile_srcdir = ${glibcxx_srcdir}/include/profile profile_builddir = ./profile profile_headers = \ + ${profile_srcdir}/array \ ${profile_srcdir}/base.h \ ${profile_srcdir}/unordered_map \ ${profile_srcdir}/unordered_set \ Index: testsuite/23_containers/array/tuple_interface/get_neg.cc =================================================================== --- testsuite/23_containers/array/tuple_interface/get_neg.cc (revision 193210) +++ testsuite/23_containers/array/tuple_interface/get_neg.cc (working copy) @@ -1,5 +1,6 @@ +// { dg-do compile } // { dg-options "-std=gnu++11" } -// { dg-do compile } +// { dg-require-normal-mode "" } // Copyright (C) 2012 Free Software Foundation, Inc. // @@ -28,5 +29,5 @@ int n3 = std::get<1>(ca); // { dg-error "static assertion failed" "" { target *-*-* } 291 } -// { dg-error "static assertion failed" "" { target *-*-* } 299 } -// { dg-error "static assertion failed" "" { target *-*-* } 307 } +// { dg-error "static assertion failed" "" { target *-*-* } 300 } +// { dg-error "static assertion failed" "" { target *-*-* } 308 } Index: testsuite/23_containers/array/tuple_interface/get_debug_neg.cc =================================================================== --- testsuite/23_containers/array/tuple_interface/get_debug_neg.cc (revision 0) +++ testsuite/23_containers/array/tuple_interface/get_debug_neg.cc (working copy) @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +// Copyright (C) 2012 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 +// . + +#include + +std::array a{}; +const std::array ca{}; + +int n1 = std::get<1>(a); +int n2 = std::get<1>(std::move(a)); +int n3 = std::get<1>(ca); + +// { dg-error "static assertion failed" "" { target *-*-* } 274 } +// { dg-error "static assertion failed" "" { target *-*-* } 283 } +// { dg-error "static assertion failed" "" { target *-*-* } 291 } Index: testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc =================================================================== --- testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (revision 193210) +++ testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (working copy) @@ -1,5 +1,6 @@ +// { dg-do compile } // { dg-options "-std=gnu++11" } -// { dg-do compile } +// { dg-require-normal-mode "" } // Copyright (C) 2012 Free Software Foundation, Inc. // Index: testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc =================================================================== --- testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc (revision 0) +++ testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc (working copy) @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +// Copyright (C) 2012 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 +// . + +#include + +typedef std::tuple_element<1, std::array>::type type; + +// { dg-error "static assertion failed" "" { target *-*-* } 314 } Index: testsuite/23_containers/array/debug/front1_neg.cc =================================================================== --- testsuite/23_containers/array/debug/front1_neg.cc (revision 0) +++ testsuite/23_containers/array/debug/front1_neg.cc (working copy) @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 run { xfail *-*-* } } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + std::array a; + a.front(); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc =================================================================== --- testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc (revision 0) +++ testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc (working copy) @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 run { xfail *-*-* } } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + std::array a; + a[0]; +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/array/debug/front2_neg.cc =================================================================== --- testsuite/23_containers/array/debug/front2_neg.cc (revision 0) +++ testsuite/23_containers/array/debug/front2_neg.cc (working copy) @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 run { xfail *-*-* } } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + constexpr std::array a; + a.front(); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc =================================================================== --- testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc (revision 0) +++ testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc (working copy) @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 run { xfail *-*-* } } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + constexpr std::array a; + a[0]; +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/array/debug/back1_neg.cc =================================================================== --- testsuite/23_containers/array/debug/back1_neg.cc (revision 0) +++ testsuite/23_containers/array/debug/back1_neg.cc (working copy) @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 run { xfail *-*-* } } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + std::array a; + a.back(); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/array/debug/back2_neg.cc =================================================================== --- testsuite/23_containers/array/debug/back2_neg.cc (revision 0) +++ testsuite/23_containers/array/debug/back2_neg.cc (working copy) @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 run { xfail *-*-* } } +// { dg-options "-std=gnu++11" } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + constexpr std::array a; + a.back(); +} + +int main() +{ + test01(); + return 0; +}