From patchwork Wed Jul 20 06:05:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Kosnik X-Patchwork-Id: 105584 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 EE1B2B6F71 for ; Wed, 20 Jul 2011 16:05:33 +1000 (EST) Received: (qmail 13135 invoked by alias); 20 Jul 2011 06:05:29 -0000 Received: (qmail 13112 invoked by uid 22791); 20 Jul 2011 06:05:27 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Jul 2011 06:05:08 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6K657qc003930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Jul 2011 02:05:07 -0400 Received: from shotwell (ovpn-113-130.phx2.redhat.com [10.3.113.130]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6K656ZP009546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 20 Jul 2011 02:05:06 -0400 Date: Tue, 19 Jul 2011 23:05:06 -0700 From: Benjamin Kosnik To: jason@redhat.com, gcc-patches@gcc.gnu.org Subject: [v3] constexpr n3291 missing bits Message-ID: <20110719230506.2a7747cb@shotwell> Mime-Version: 1.0 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 While reviewing the state of gcc constexpr vs. ISO C++, I noticed that the bitset access operator was missing, so I added it thusly. Like ice cream on a hot summer day, the expanded constexpr diagnostics do not disappoint. Thanks Jason! An example: testsuite/23_containers/bitset/operations/constexpr.cc:28:31: error: call to non-constexpr function ‘constexpr bool std::bitset<_Nb>::operator[](std::size_t) const [with long unsigned int _Nb = 6ul, std::size_t = long unsigned int]’ In file included from bitset:1126:7: note: ‘constexpr bool std::bitset<_Nb>::operator[](std::size_t) const [with long unsigned int _Nb = 6ul, std::size_t = long unsigned int]’ is not constexpr because it does not satisfy the requirements: bitset:1127:42: error: call to non-constexpr function ‘constexpr bool std::bitset<_Nb>::_Unchecked_test(std::size_t) const [with long unsigned int _Nb = 6ul, std::size_t = long unsigned int]’ bitset:1021:7: note: ‘constexpr bool std::bitset<_Nb>::_Unchecked_test(std::size_t) const [with long unsigned int _Nb = 6ul, std::size_t = long unsigned int]’ is not constexpr because it does not satisfy the requirements: bitset:1023:28: error: call to non-constexpr function ‘std::_Base_bitset<1ul>::_WordT std::_Base_bitset<1ul>::_M_getword(std::size_t) const’ Yay! This makes speculating about constexpr much easier to debug. tested x86/linux -benjamin Index: include/std/bitset =================================================================== --- include/std/bitset (revision 176490) +++ include/std/bitset (working copy) @@ -111,7 +111,7 @@ _M_getword(size_t __pos) _GLIBCXX_NOEXCEPT { return _M_w[_S_whichword(__pos)]; } - _WordT + _GLIBCXX_CONSTEXPR _WordT _M_getword(size_t __pos) const _GLIBCXX_NOEXCEPT { return _M_w[_S_whichword(__pos)]; } @@ -221,12 +221,11 @@ // find first "on" bit size_t - _M_do_find_first(size_t __not_found) const _GLIBCXX_NOEXCEPT; + _M_do_find_first(size_t) const _GLIBCXX_NOEXCEPT; // find the next "on" bit that follows "prev" size_t - _M_do_find_next(size_t __prev, size_t __not_found) const - _GLIBCXX_NOEXCEPT; + _M_do_find_next(size_t, size_t) const _GLIBCXX_NOEXCEPT; }; // Definitions of non-inline functions from _Base_bitset. @@ -405,7 +404,7 @@ _M_getword(size_t) _GLIBCXX_NOEXCEPT { return _M_w; } - _WordT + _GLIBCXX_CONSTEXPR _WordT _M_getword(size_t) const _GLIBCXX_NOEXCEPT { return _M_w; } @@ -557,7 +556,7 @@ return *new _WordT; } - _WordT + _GLIBCXX_CONSTEXPR _WordT _M_getword(size_t __pos) const _GLIBCXX_NOEXCEPT { return 0; } @@ -1017,7 +1016,7 @@ return *this; } - bool + _GLIBCXX_CONSTEXPR bool _Unchecked_test(size_t __pos) const _GLIBCXX_NOEXCEPT { return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos)) != static_cast<_WordT>(0)); } @@ -1122,7 +1121,7 @@ operator[](size_t __position) { return reference(*this, __position); } - bool + _GLIBCXX_CONSTEXPR bool operator[](size_t __position) const { return _Unchecked_test(__position); } //@} Index: testsuite/23_containers/bitset/operations/constexpr.cc =================================================================== --- testsuite/23_containers/bitset/operations/constexpr.cc (revision 0) +++ testsuite/23_containers/bitset/operations/constexpr.cc (revision 0) @@ -0,0 +1,40 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2011 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 + +int main() +{ + // bitset base type + typedef std::_Base_bitset<6> bitset_base; + constexpr bitset_base base = bitset_base(); + + constexpr auto r1 = base._M_getword(2); + // constexpr auto r2 = base._M_getdata(); // error, pointer to this + auto r2 = base._M_getdata(); + constexpr auto r3 = base._M_hiword(); + + // bitset operators + typedef std::bitset<6> bitset_type; + constexpr bitset_type a = bitset_type(); + constexpr auto v = a[0]; + + return 0; +}