From patchwork Sat Nov 19 11:53:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 126539 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 6EFD7B722B for ; Sat, 19 Nov 2011 22:54:18 +1100 (EST) Received: (qmail 17214 invoked by alias); 19 Nov 2011 11:54:14 -0000 Received: (qmail 17197 invoked by uid 22791); 19 Nov 2011 11:54:13 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 19 Nov 2011 11:54:00 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pAJBrxGU027915 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 19 Nov 2011 11:53:59 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pAJBrwmh000546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 19 Nov 2011 11:53:58 GMT Received: from abhmt104.oracle.com (abhmt104.oracle.com [141.146.116.56]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id pAJBrrJO021737; Sat, 19 Nov 2011 05:53:53 -0600 Received: from [192.168.1.4] (/79.51.26.160) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 19 Nov 2011 03:53:49 -0800 Message-ID: <4EC798A8.9000503@oracle.com> Date: Sat, 19 Nov 2011 12:53:12 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Fix bitset::operator[] const in debug/profile mode 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, noticed this while investigating the spurious failure of bitset/operations/constexpr.cc in debug-mode. Unfortunately debug-mode bitset checking is pretty weak in C++0x mode (for other reasons too), but at least now the operator is conforming and the testsuite is clean. Committed to mainline. Thanks, Paolo. ///////////////// 2011-11-19 Paolo Carlini * include/debug/bitset (operator[](size_t) const): Declare constexpr. * include/profile/bitset: Likewise. * testsuite/23_containers/bitset/operations/constexpr.cc: Split out non portable bits to... * testsuite/23_containers/bitset/operations/constexpr-2.cc: ... here. Index: include/debug/bitset =================================================================== --- include/debug/bitset (revision 181505) +++ include/debug/bitset (working copy) @@ -51,7 +51,7 @@ public: // In C++0x we rely on normal reference type to preserve the property // of bitset to be use as a literal. - // TODO: Find an other solution. + // TODO: Find another solution. #ifdef __GXX_EXPERIMENTAL_CXX0X__ typedef typename _Base::reference reference; #else @@ -272,11 +272,14 @@ // _GLIBCXX_RESOLVE_LIB_DEFECTS // 11. Bitset minor problems - bool + _GLIBCXX_CONSTEXPR bool operator[](size_t __pos) const { +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + // TODO: Check in debug-mode too. __glibcxx_check_subscript(__pos); - return _M_base()[__pos]; +#endif + return _Base::operator[](__pos); } using _Base::to_ulong; Index: include/profile/bitset =================================================================== --- include/profile/bitset (revision 181505) +++ include/profile/bitset (working copy) @@ -232,10 +232,10 @@ // _GLIBCXX_RESOLVE_LIB_DEFECTS // 11. Bitset minor problems - bool + _GLIBCXX_CONSTEXPR bool operator[](size_t __pos) const { - return _M_base()[__pos]; + return _Base::operator[](__pos); } using _Base::to_ulong; Index: testsuite/23_containers/bitset/operations/constexpr-2.cc =================================================================== --- testsuite/23_containers/bitset/operations/constexpr-2.cc (revision 181505) +++ testsuite/23_containers/bitset/operations/constexpr-2.cc (working copy) @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-mode "" } // { dg-options "-std=gnu++0x" } // Copyright (C) 2011 Free Software Foundation, Inc. @@ -31,10 +32,5 @@ auto r2 __attribute__((unused)) = base._M_getdata(); constexpr auto r3 __attribute__((unused)) = base._M_hiword(); - // bitset operators - typedef std::bitset<6> bitset_type; - constexpr bitset_type a = bitset_type(); - constexpr auto v __attribute__((unused)) = a[0]; - return 0; } Index: testsuite/23_containers/bitset/operations/constexpr.cc =================================================================== --- testsuite/23_containers/bitset/operations/constexpr.cc (revision 181505) +++ testsuite/23_containers/bitset/operations/constexpr.cc (working copy) @@ -22,15 +22,6 @@ int main() { - // bitset base type - typedef std::_Base_bitset<6> bitset_base; - constexpr bitset_base base = bitset_base(); - - constexpr auto r1 __attribute__((unused)) = base._M_getword(2); - // constexpr auto r2 = base._M_getdata(); // error, pointer to this - auto r2 __attribute__((unused)) = base._M_getdata(); - constexpr auto r3 __attribute__((unused)) = base._M_hiword(); - // bitset operators typedef std::bitset<6> bitset_type; constexpr bitset_type a = bitset_type();