aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@redhat.com>2011-07-20 15:44:18 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2011-07-20 15:44:18 +0000
commit07be61200c8b5ed4b686450d57a590eaeffe66c7 (patch)
tree873f613634a39854acddbb6e270df0b8c9aea14f
parent02aec184ceac620e40e15dbb78fa7d43d4a40972 (diff)
downloadgcc-07be61200c8b5ed4b686450d57a590eaeffe66c7.zip
gcc-07be61200c8b5ed4b686450d57a590eaeffe66c7.tar.gz
gcc-07be61200c8b5ed4b686450d57a590eaeffe66c7.tar.bz2
bitset (operator[]): Make constexpr.
2011-07-20 Benjamin Kosnik <bkoz@redhat.com> * include/std/bitset (operator[]): Make constexpr. * testsuite/23_containers/bitset/operations/constexpr.cc: New. From-SVN: r176519
-rw-r--r--libstdc++-v3/ChangeLog5
-rw-r--r--libstdc++-v3/include/std/bitset15
-rw-r--r--libstdc++-v3/testsuite/23_containers/bitset/operations/constexpr.cc40
3 files changed, 52 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 519f9cb..d5b7598 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,8 @@
+2011-07-20 Benjamin Kosnik <bkoz@redhat.com>
+
+ * include/std/bitset (operator[]): Make constexpr.
+ * testsuite/23_containers/bitset/operations/constexpr.cc: New.
+
2011-07-20 Paolo Carlini <paolo.carlini@oracle.com>
* include/debug/safe_local_iterator.h (_Safe_local_iterator<>::
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 6d23df2..f880e72 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -111,7 +111,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_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 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
// 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 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_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 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
return *new _WordT;
}
- _WordT
+ _GLIBCXX_CONSTEXPR _WordT
_M_getword(size_t __pos) const _GLIBCXX_NOEXCEPT
{ return 0; }
@@ -1017,7 +1016,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
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 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
operator[](size_t __position)
{ return reference(*this, __position); }
- bool
+ _GLIBCXX_CONSTEXPR bool
operator[](size_t __position) const
{ return _Unchecked_test(__position); }
//@}
diff --git a/libstdc++-v3/testsuite/23_containers/bitset/operations/constexpr.cc b/libstdc++-v3/testsuite/23_containers/bitset/operations/constexpr.cc
new file mode 100644
index 0000000..9f0fa3d
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/bitset/operations/constexpr.cc
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+#include <bitset>
+
+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;
+}