This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++0x constexpr PATCHes #11-13: library usage


These three patches integrate constexpr into libstdc++ as specified by the latest working paper...or sometimes as not yet specified by the working paper. The first patch, constexpr-initlist.patch, allows for use of std::initializer_list in constant expressions. The rest is Benjamin's work.

This, of course, is waiting for the compiler support to be checked in.


commit 882dd71a76da7cdde690ae23fcca29d4a54c6bc2
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Oct 27 12:43:11 2010 -0400

    	* libsupc++/initializer_list: Decorate with constexpr.

diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist2.C
new file mode 100644
index 0000000..f34b980
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist2.C
@@ -0,0 +1,10 @@
+// { dg-options -std=c++0x }
+
+#include <initializer_list>
+
+constexpr auto list = { 1, 2, 3, 4 };
+
+#define SA(X) static_assert(X, #X)
+SA(list.size() == 4);
+SA(list.begin()[2] == 3);
+SA(list.end()[-1] == 4);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist3.C
new file mode 100644
index 0000000..7620e6b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist3.C
@@ -0,0 +1,12 @@
+// { dg-options -std=c++0x }
+
+#include <initializer_list>
+#define SA(X) static_assert(X,#X)
+
+constexpr int f(std::initializer_list<int> l) { return l.begin()[0]; }
+
+int main()
+{
+  constexpr int i = f({42});
+  SA(i==42);
+}
diff --git a/libstdc++-v3/libsupc++/initializer_list b/libstdc++-v3/libsupc++/initializer_list
index 0006b70..1048d44 100644
--- a/libstdc++-v3/libsupc++/initializer_list
+++ b/libstdc++-v3/libsupc++/initializer_list
@@ -57,23 +57,23 @@ namespace std
       size_type			_M_len;
 
       // The compiler can call a private constructor.
-      initializer_list(const_iterator __a, size_type __l)
+      constexpr initializer_list(const_iterator __a, size_type __l)
       : _M_array(__a), _M_len(__l) { }
 
     public:
-      initializer_list() : _M_array(0), _M_len(0) { }
+      constexpr initializer_list() : _M_array(0), _M_len(0) { }
 
       // Number of elements.
-      size_type
-      size() const { return _M_len; }
+      constexpr size_type
+      size() { return _M_len; }
 
       // First element.
-      const_iterator
-      begin() const { return _M_array; }
+      constexpr const_iterator
+      begin() { return _M_array; }
 
       // One past the last element.
-      const_iterator
-      end() const { return begin() + size(); }
+      constexpr const_iterator
+      end() { return begin() + size(); }
   };
 
   /**
@@ -82,7 +82,7 @@ namespace std
    *  @param  il  Initializer list.
    */
   template<class _Tp>
-    inline const _Tp*
+    constexpr const _Tp*
     begin(initializer_list<_Tp> __ils)
     { return __ils.begin(); }
 
@@ -92,7 +92,7 @@ namespace std
    *  @param  il  Initializer list.
    */
   template<class _Tp>
-    inline const _Tp*
+    constexpr const _Tp*
     end(initializer_list<_Tp> __ils)
     { return __ils.end(); }
 }

commit 5afe052b2dea48995861925fec11eb055508b726
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Oct 31 22:17:21 2010 -0400

    	* include/std/chrono (duration): Remove defaulted constructor,
    	replace with mem-init list.
    	* testsuite/20_util/duration/cons/constexpr.cc: Add single value.
    	* testsuite/20_util/duration/requirements/constexpr_functions.cc:
    	Add non-static member functions.
    
    	* testsuite/20_util/default_delete/cons/constexpr.cc: New, xfail.
    	* testsuite/20_util/enable_shared_from_this/cons/constexpr.cc: Same.
    	* testsuite/20_util/shared_ptr/cons/constexpr.cc: Same.
    	* testsuite/20_util/time_point/requirements/constexpr_functions.cc:
    	Same.
    	* testsuite/20_util/unique_ptr/cons/constexpr.cc: Same.
    	* testsuite/20_util/weak_ptr/cons/constexpr.cc: Same.
    
    	* include/std/bitset: Add constexpr as per N3126 draft.
    	* testsuite/23_containers/bitset/cons/constexpr.cc: New.
    	* testsuite/23_containers/bitset/requirements/constexpr_functions.cc:
    	New.

diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 1c71c4f..e392ae6 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -72,36 +72,39 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       /// 0 is the least significant word.
       _WordT 		_M_w[_Nw];
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      constexpr _Base_bitset() : _M_w({ }) { }
+
+      constexpr _Base_bitset(unsigned long long __val)
+      : _M_w({ __val
+#if (__LONG_LONG_MAX__ * 2ULL + 1) > (__LONG_MAX__ * 2UL + 1)
+	       , __val >> _GLIBCXX_BITSET_BITS_PER_WORD
+#endif
+       }) { }
+#else
       _Base_bitset()
       { _M_do_reset(); }
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-      _Base_bitset(unsigned long long __val)
-#else
       _Base_bitset(unsigned long __val)
-#endif
       {
 	_M_do_reset();
 	_M_w[0] = __val;
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-	if (sizeof(unsigned long long) > sizeof(unsigned long))
-	  _M_w[1] = __val >> _GLIBCXX_BITSET_BITS_PER_WORD;
-#endif
       }
+#endif
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichword(size_t __pos )
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichbyte(size_t __pos )
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichbit(size_t __pos )
       { return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static _WordT
+      static _GLIBCXX_CONSTEXPR _WordT
       _S_maskbit(size_t __pos )
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
@@ -123,7 +126,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       _M_hiword()
       { return _M_w[_Nw - 1]; }
 
-      _WordT
+      _GLIBCXX_CONSTEXPR _WordT
       _M_hiword() const
       { return _M_w[_Nw - 1]; }
 
@@ -368,31 +371,31 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       typedef unsigned long _WordT;
       _WordT _M_w;
 
-      _Base_bitset(void)
+      _GLIBCXX_CONSTEXPR _Base_bitset()
       : _M_w(0)
       { }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      _Base_bitset(unsigned long long __val)
+      constexpr _Base_bitset(unsigned long long __val)
 #else
       _Base_bitset(unsigned long __val)
 #endif
       : _M_w(__val)
       { }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichword(size_t __pos )
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichbyte(size_t __pos )
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichbit(size_t __pos )
       {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static _WordT
+      static _GLIBCXX_CONSTEXPR _WordT
       _S_maskbit(size_t __pos )
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
@@ -414,7 +417,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       _M_hiword()
       { return _M_w; }
 
-      _WordT
+      _GLIBCXX_CONSTEXPR _WordT
       _M_hiword() const
       { return _M_w; }
 
@@ -511,29 +514,29 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
     {
       typedef unsigned long _WordT;
 
-      _Base_bitset()
+      _GLIBCXX_CONSTEXPR _Base_bitset()
       { }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      _Base_bitset(unsigned long long)
+      constexpr _Base_bitset(unsigned long long)
 #else
       _Base_bitset(unsigned long)
 #endif
       { }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichword(size_t __pos )
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichbyte(size_t __pos )
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
-      static size_t
+      static _GLIBCXX_CONSTEXPR size_t
       _S_whichbit(size_t __pos )
       {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static _WordT
+      static _GLIBCXX_CONSTEXPR _WordT
       _S_maskbit(size_t __pos )
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
@@ -545,13 +548,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       // make an unchecked call; all the memory ugliness is therefore
       // localized to this single should-never-get-this-far function.
       _WordT&
-      _M_getword(size_t) const
+      _M_getword(size_t)
       { 
 	__throw_out_of_range(__N("_Base_bitset::_M_getword")); 
 	return *new _WordT; 
       }
 
       _WordT
+      _M_getword(size_t __pos) const
+      { return 0; }
+
+      _GLIBCXX_CONSTEXPR _WordT
       _M_hiword() const
       { return 0; }
 
@@ -632,13 +639,21 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
   template<size_t _Extrabits>
     struct _Sanitize
     {
-      static void _S_do_sanitize(unsigned long& __val)
-      { __val &= ~((~static_cast<unsigned long>(0)) << _Extrabits); }
+      typedef unsigned long _WordT;
+
+      static void 
+      _S_do_sanitize(_WordT& __val)
+      { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
     };
 
   template<>
     struct _Sanitize<0>
-    { static void _S_do_sanitize(unsigned long) {} };
+    { 
+      typedef unsigned long _WordT;
+
+      static void 
+      _S_do_sanitize(_WordT) { } 
+    };
 
   /**
    *  @brief  The %bitset class represents a @e fixed-size sequence of bits.
@@ -713,11 +728,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       typedef unsigned long _WordT;
 
       void
-	_M_do_sanitize()
-	{
-	  _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD>::
-	    _S_do_sanitize(this->_M_hiword());
-	}
+      _M_do_sanitize()
+      { 
+	typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
+	__sanitize_type::_S_do_sanitize(this->_M_hiword());
+      }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       template<typename> friend class hash;
@@ -740,8 +755,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       {
 	friend class bitset;
 
-	_WordT *_M_wp;
-	size_t _M_bpos;
+	_WordT*	_M_wp;
+	size_t 	_M_bpos;
 	
 	// left undefined
 	reference();
@@ -799,17 +814,18 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
       // 23.3.5.1 constructors:
       /// All bits set to zero.
-      bitset()
+      _GLIBCXX_CONSTEXPR bitset()
       { }
 
       /// Initial bits bitwise-copied from a single word (others set to zero).
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      bitset(unsigned long long __val)
+      constexpr bitset(unsigned long long __val)
+      : _Base(__val) { }
 #else
       bitset(unsigned long __val)
-#endif
       : _Base(__val)
       { _M_do_sanitize(); }
+#endif
 
       /**
        *  @brief  Use a subset of a string.
@@ -1088,8 +1104,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       /**
        *  @brief  Array-indexing support.
        *  @param  position  Index into the %bitset.
-       *  @return  A bool for a <em>const %bitset</em>.  For non-const bitsets, an
-       *           instance of the reference proxy class.
+       *  @return A bool for a <em>const %bitset</em>.  For non-const
+       *           bitsets, an instance of the reference proxy class.
        *  @note  These operators do no range checking and throw no exceptions,
        *         as required by DR 11 to the standard.
        *
@@ -1101,7 +1117,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        */
       reference
       operator[](size_t __position)
-      { return reference(*this,__position); }
+      { return reference(*this, __position); }
 
       bool
       operator[](size_t __position) const
@@ -1236,7 +1252,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       { return this->_M_do_count(); }
 
       /// Returns the total number of bits.
-      size_t
+      _GLIBCXX_CONSTEXPR size_t
       size() const
       { return _Nb; }
 
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index f119d71..c539e92 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -209,7 +209,7 @@ namespace std
 	static_assert(_Period::num > 0, "period must be positive");
 
 	// 20.8.3.1 construction / copy / destroy
-	duration() = default;
+	constexpr duration() : __r() { }
 
 	template<typename _Rep2, typename = typename
 	       enable_if<is_convertible<_Rep2, rep>::value
@@ -490,9 +490,9 @@ namespace std
     template<typename _Clock, typename _Duration>
       struct time_point
       {
-	typedef _Clock                    	clock;
-	typedef _Duration                 	duration;
-	typedef typename duration::rep    	rep;
+	typedef _Clock			  	clock;
+	typedef _Duration		  	duration;
+	typedef typename duration::rep	  	rep;
 	typedef typename duration::period	period;
 
 	time_point() : __d(duration::zero())
diff --git a/libstdc++-v3/testsuite/20_util/default_delete/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/default_delete/cons/constexpr.cc
new file mode 100644
index 0000000..897394a
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/default_delete/cons/constexpr.cc
@@ -0,0 +1,29 @@
+// { dg-do compile { xfail *-*-* } }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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 <memory>
+#include <testsuite_common_types.h>
+
+int main()
+{
+  __gnu_test::constexpr_default_constructible test;
+  test.operator()<std::default_delete<int>>(); // { dg-excess-errors "" }
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/duration/cons/constexpr.cc
index 0161e47..5f99454 100644
--- a/libstdc++-v3/testsuite/20_util/duration/cons/constexpr.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/cons/constexpr.cc
@@ -23,7 +23,11 @@
 
 int main()
 {
-  __gnu_test::constexpr_default_constructible test;
-  //  test.operator()<std::chrono::duration<long>>();
+  __gnu_test::constexpr_default_constructible test1;
+  test1.operator()<std::mega>();
+  test1.operator()<std::chrono::seconds>();
+
+  __gnu_test::constexpr_single_value_constructible test2;
+  test2.operator()<std::chrono::seconds, std::chrono::seconds::rep>();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/constexpr_functions.cc
index 4e53d4b..3986659 100644
--- a/libstdc++-v3/testsuite/20_util/duration/requirements/constexpr_functions.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/requirements/constexpr_functions.cc
@@ -36,6 +36,11 @@ namespace __gnu_test
 	    constexpr auto v1(_Ttesttype::min());
 	    constexpr auto v2(_Ttesttype::max());
 	    constexpr auto v3(_Ttesttype::zero());
+
+	    constexpr _Ttesttype obj { };
+	    constexpr auto v4 = obj.count();
+	    constexpr auto v5 = -obj;
+	    constexpr auto v6 = +obj;
 	  }
 	};
 
@@ -48,6 +53,6 @@ namespace __gnu_test
 int main()
 {
   __gnu_test::constexpr_member_functions test;
-  test.operator()<std::chrono::duration<long>>();
+  test.operator()<std::chrono::nanoseconds>();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/cons/constexpr.cc
new file mode 100644
index 0000000..0df6dcf3
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/cons/constexpr.cc
@@ -0,0 +1,35 @@
+// { dg-do compile { xfail *-*-* } }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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 <memory>
+#include <testsuite_common_types.h>
+
+struct derived : public std::enable_shared_from_this<int>
+{
+  constexpr derived() { }
+};
+
+int main()
+{
+  __gnu_test::constexpr_default_constructible test;
+  test.operator()<derived>();  // { dg-excess-errors "" }
+  derived d;
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/hash/chi2_quality.cc b/libstdc++-v3/testsuite/20_util/hash/chi2_quality.cc
index a105f4b..4c2f09e 100644
--- a/libstdc++-v3/testsuite/20_util/hash/chi2_quality.cc
+++ b/libstdc++-v3/testsuite/20_util/hash/chi2_quality.cc
@@ -91,8 +91,10 @@ test_uniform_random()
   while (set.size() < N)
     {
       s.clear();
-      for (unsigned int i = 0; i < len; ++i)
-	s.push_back(rand() % 128);
+      for (int i = 0; i < len; ++i)
+        {
+          s.push_back(rand() % 128);
+        }
       set.insert(s);
     }
 
@@ -120,7 +122,7 @@ test_bit_flip_set()
   while (set.size() < N)
     {
       std::string s(base, base+len);
-      for (unsigned int i = 0; i < bits_to_flip; ++i)
+      for (int i = 0; i < bits_to_flip; ++i)
         {
           int bit = rand() % bitlen;
           s[bit/8] ^= (1 << (bit%8));
@@ -166,7 +168,7 @@ test_bit_string_set()
   for (unsigned long i = 0; i < N; ++i)
     {
       s.clear();
-      for (unsigned int j = 0; j < sizeof(unsigned long) * 8; ++j)
+      for (int j = 0; j < sizeof(unsigned long) * 8; ++j)
         {
           const bool bit = (1UL << j) & i;
           s.push_back(bit ? '1' : '0');
diff --git a/libstdc++-v3/testsuite/20_util/hash/quality.cc b/libstdc++-v3/testsuite/20_util/hash/quality.cc
index 8a6edac..3e3951f 100644
--- a/libstdc++-v3/testsuite/20_util/hash/quality.cc
+++ b/libstdc++-v3/testsuite/20_util/hash/quality.cc
@@ -37,12 +37,12 @@ using namespace std;
 #define STRSIZE 42
 #endif
 
-const unsigned int num_quality_tests = NTESTS;
-const unsigned int num_strings_for_quality_tests = NSTRINGS;
-const unsigned int string_size = STRSIZE;
+const int num_quality_tests = NTESTS;
+const int num_strings_for_quality_tests = NSTRINGS;
+const int string_size = STRSIZE;
 
 vector<string>
-random_strings(unsigned int n, unsigned int len)
+random_strings(int n, int len)
 {
   string s(len, '\0');
   unordered_set<string> result_set;
@@ -57,10 +57,10 @@ random_strings(unsigned int n, unsigned int len)
 }
 
 double
-score_from_varying_position(string s, unsigned int index)
+score_from_varying_position(string s, int index)
 {
   bool test __attribute__((unused)) = true;
-  unsigned int bits_in_hash_code = sizeof(size_t) * 8;
+  int bits_in_hash_code = sizeof(size_t) * 8;
 
   // We'll iterate through all 256 vals for s[index], leaving the rest
   // of s fixed.  Then, for example, out of the 128 times that
@@ -71,9 +71,9 @@ score_from_varying_position(string s, unsigned int index)
   // count the number of times each output position (of which there are
   // bits_in_hash_code) is 1 for each bit position within s[index] (of 
   // which there are 8) and value of that bit (of which there are 2).
-  const unsigned int jj = 2;
-  const unsigned int kk = jj * bits_in_hash_code;
-  const unsigned int array_size = 8 * kk;
+  const int jj = 2;
+  const int kk = jj * bits_in_hash_code;
+  const int array_size = 8 * kk;
   vector<int> ones(array_size, 0);
 
   for (int i = 0; i < 256; i++)
@@ -99,7 +99,7 @@ score_from_varying_position(string s, unsigned int index)
   int good = 0, bad = 0;
   for (int bit = 0; bit <= 1; bit++)
     {
-      for (unsigned int j = 0; j < bits_in_hash_code; j++)
+      for (int j = 0; j < bits_in_hash_code; j++)
         {
           for (int bitpos = 0; bitpos < 8; bitpos++)
             {
@@ -121,21 +121,21 @@ score_from_varying_position(string s, unsigned int index)
 }
 
 double
-score_from_varying_position(const vector<string>& v, unsigned int index)
+score_from_varying_position(const vector<string>& v, int index)
 {
   double score = 0;
-  for (unsigned int i = 0; i < v.size(); i++)
+  for (int i = 0; i < v.size(); i++)
     score += score_from_varying_position(v[i], index);
   return score / v.size();
 }
 
 double
-quality_test(unsigned int num_strings, unsigned int string_size)
+quality_test(int num_strings, int string_size)
 {
   // Construct random strings.
   vector<string> v = random_strings(num_strings, string_size);
   double sum_of_scores = 0;
-  for (unsigned int i = 0; i < string_size; i++)
+  for (int i = 0; i < string_size; i++)
     sum_of_scores += score_from_varying_position(v, i);
 
   // A good hash function should have a score very close to 1, and a bad
@@ -149,7 +149,7 @@ quality_test()
   bool test __attribute__((unused)) = true;
   srand(137);
   double sum_of_scores = 0;
-  for (unsigned int i = 0; i < num_quality_tests; i++)
+  for (int i = 0; i < num_quality_tests; i++)
     {
       double score = quality_test(num_strings_for_quality_tests,
 				  string_size);
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/constexpr.cc
new file mode 100644
index 0000000..d040ea4
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/constexpr.cc
@@ -0,0 +1,33 @@
+// { dg-do compile { xfail *-*-* } }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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 <memory>
+#include <testsuite_common_types.h>
+
+int main()
+{
+  __gnu_test::constexpr_default_constructible test1;
+  test1.operator()<std::shared_ptr<int>>();  // { dg-excess-errors "" }
+
+  __gnu_test::constexpr_single_value_constructible test2;
+  test2.operator()<std::shared_ptr<int>, std::nullptr_t>();  // { dg-excess-errors "" }
+
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/time_point/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/20_util/time_point/requirements/constexpr_functions.cc
new file mode 100644
index 0000000..5bdf088
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/time_point/requirements/constexpr_functions.cc
@@ -0,0 +1,59 @@
+// { dg-do compile { xfail *-*-* } }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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 <chrono>
+#include <testsuite_common_types.h>
+
+namespace __gnu_test
+{
+  struct constexpr_member_functions
+  {
+    template<typename _Ttesttype>
+      void
+      operator()()
+      {
+	struct _Concept
+	{
+	  void __constraint()
+	  {
+#if 1
+	    constexpr auto v1(_Ttesttype::min());
+	    constexpr auto v2(_Ttesttype::max());
+#else
+	    constexpr _Ttesttype obj;
+	    constexpr auto v1 = obj.min();
+	    constexpr auto v2 = obj.max();
+#endif
+	  }
+	};
+
+	_Concept c;
+	c.__constraint();
+      }
+  };
+}
+
+int main()
+{
+  using namespace std::chrono;
+  __gnu_test::constexpr_member_functions test;
+  test.operator()<time_point<system_clock>>();  // { dg-excess-errors "" }
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/constexpr.cc
new file mode 100644
index 0000000..20db761
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/constexpr.cc
@@ -0,0 +1,32 @@
+// { dg-do compile { xfail *-*-* } }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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 <memory>
+#include <testsuite_common_types.h>
+
+int main()
+{
+  __gnu_test::constexpr_default_constructible test1;
+  test1.operator()<std::unique_ptr<int>>();  // { dg-excess-errors "" }
+
+  __gnu_test::constexpr_single_value_constructible test2;
+  test2.operator()<std::unique_ptr<int>, std::nullptr_t>();  // { dg-excess-errors "" }
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/cons/constexpr.cc
new file mode 100644
index 0000000..3b43769
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/weak_ptr/cons/constexpr.cc
@@ -0,0 +1,32 @@
+// { dg-do compile { xfail *-*-* } }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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 <memory>
+#include <testsuite_common_types.h>
+
+int main()
+{
+  __gnu_test::constexpr_default_constructible test;
+  test.operator()<std::weak_ptr<int>>();  // { dg-excess-errors "" }
+  //  test.operator()<std::__weak_ptr<int>>();
+  //  test.operator()<std::__weak_count<__gnu_cxx::__default_lock_policy>>();
+  // test.operator()<std::_Sp_counted_base<__gnu_cxx::__default_lock_policy>>();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/constexpr.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/constexpr.cc
new file mode 100644
index 0000000..aea5030
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/constexpr.cc
@@ -0,0 +1,37 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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>
+#include <testsuite_common_types.h>
+
+int main()
+{
+  __gnu_test::constexpr_default_constructible test1;
+  test1.operator()<std::bitset<0>>();
+  test1.operator()<std::bitset<1>>();
+  test1.operator()<std::bitset<256>>();
+
+  __gnu_test::constexpr_single_value_constructible test2;
+  test2.operator()<std::bitset<0>, unsigned long long>();
+  test2.operator()<std::bitset<1>, unsigned long long>();
+  test2.operator()<std::bitset<256>, unsigned long long>();
+
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc
index e261ce5..e585651 100644
--- a/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc
+++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc
@@ -45,7 +45,7 @@ void test01()
   VERIFY( bitset<4>(s1, 4) == test01_ref<4>(s1, 4) );
 
   const char s2[3] = { '1', '1', '0' };
-  VERIFY( bitset<6>(s2, 3) == test01_ref<6>(s2, 3) );
+  VERIFY( bitset<6>(s1, 3) == test01_ref<6>(s1, 3) );
 
   const char* s3 = "1110110";
   VERIFY( bitset<7>(s3) == test01_ref<7>(s3) );
diff --git a/libstdc++-v3/testsuite/23_containers/bitset/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/23_containers/bitset/requirements/constexpr_functions.cc
new file mode 100644
index 0000000..ac9a07f
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/bitset/requirements/constexpr_functions.cc
@@ -0,0 +1,55 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 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>
+#include <testsuite_common_types.h>
+
+namespace __gnu_test
+{
+  struct constexpr_member_functions
+  {
+    template<typename _Ttesttype>
+      void
+      operator()()
+      {
+	struct _Concept
+	{
+	  void __constraint()
+	  { 
+            constexpr _Ttesttype obj;
+            constexpr auto v1 = obj.size();
+	    //	    constexpr auto v2 = obj[4];
+	  }
+	};
+
+	_Concept c;
+	c.__constraint();
+      }
+  };
+}
+
+int main()
+{
+  __gnu_test::constexpr_member_functions test;
+  test.operator()<std::bitset<0>>();
+  test.operator()<std::bitset<1>>();
+  test.operator()<std::bitset<64>>();
+  return 0;
+}

Attachment: constexpr-lib1.patch.bz2
Description: application/bzip


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]