From: Paolo Carlini Date: Mon, 27 Oct 2008 16:50:23 +0000 (+0000) Subject: re PR libstdc++/37919 ([c++0x] GCC 4.4 regression r141214 of gcc c++0x stl_pair.c... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f0f2a1dfd96bc496c50a264d2482daa254490aa;p=gcc.git re PR libstdc++/37919 ([c++0x] GCC 4.4 regression r141214 of gcc c++0x stl_pair.c causes a boost 1.36 compilation to fail) 2008-10-27 Paolo Carlini PR libstdc++/37919 Revert: 2008-10-18 Douglas Gregor * include/bits/stl_pair.h (__may_be_null_pointer_init): New. (pair::pair): Eliminate the redundant pair(U1&&, U2&&) constructor. Add lvalue pair constructor to handle non-const pair lvalues. Remove the old variadic constructor, and instead provide several variadic constructors that avoid failing when attempting to initialize a pointer from a null pointer constant. * testsuite/20_util/pair/moveable.cc (test3): Add new tests with initialization of pointers from the null pointer constant. From-SVN: r141388 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index af59f638307..4230bc6a129 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,18 @@ +2008-10-27 Paolo Carlini + + PR libstdc++/37919 + Revert: + 2008-10-18 Douglas Gregor + + * include/bits/stl_pair.h (__may_be_null_pointer_init): New. + (pair::pair): Eliminate the redundant pair(U1&&, U2&&) constructor. + Add lvalue pair constructor to handle non-const pair lvalues. + Remove the old variadic constructor, and instead provide several + variadic constructors that avoid failing when attempting to + initialize a pointer from a null pointer constant. + * testsuite/20_util/pair/moveable.cc (test3): Add new tests with + initialization of pointers from the null pointer constant. + 2008-10-27 Paolo Carlini PR libstdc++/37522 diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index c169275ece3..cf61b09945a 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -65,35 +65,8 @@ #include // for std::move / std::forward, std::decay, and // std::swap -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -#include -#endif - _GLIBCXX_BEGIN_NAMESPACE(std) -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -// A trait that determines whether the initialization of a T from -// arguments of type Args could possibly be the initialization of a -// pointer from a null pointer constant. -template -struct __may_be_null_pointer_init - : public false_type { }; - -template -struct __may_be_null_pointer_init<_Tp*, _Up> - : public integral_constant::type>::value - || is_enum::type>::value)> - { }; - -template -struct __may_be_null_pointer_init<_Tp _Class::*, _Up> - : public integral_constant::type>::value - || is_enum::type>::value)> - { }; -#endif - /// pair holds two objects of arbitrary type. template struct pair @@ -116,12 +89,10 @@ struct __may_be_null_pointer_init<_Tp _Class::*, _Up> : first(__a), second(__b) { } #ifdef __GXX_EXPERIMENTAL_CXX0X__ - // Omitted the following constructor, which appears in the C++0x - // working paper but is redundant with the variadic constructors - // below. - // - // template - // pair(_U1&& __x, _U2&& __y); + template + pair(_U1&& __x, _U2&& __y) + : first(std::forward<_U1>(__x)), + second(std::forward<_U2>(__y)) { } pair(pair&& __p) : first(std::move(__p.first)), @@ -140,56 +111,12 @@ struct __may_be_null_pointer_init<_Tp _Class::*, _Up> : first(std::move(__p.first)), second(std::move(__p.second)) { } - // This constructor is required so that lvalue pairs don't get - // pushed to the variadic constructor below. - template - pair(pair<_U1, _U2>& __p) - : first(const_cast&>(__p).first), - second(const_cast&>(__p).second) { } - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 811. pair of pointers no longer works with literal 0 - - // Variadic constructor. The enable_if makes sure that we won't - // try to initialize a pointer from an integral type, which - // needs to be handled by a different constructor that will - // convert a null pointer constant to that pointer type. See - // library issue 767. - template::value - && !__may_be_null_pointer_init<_T2, _Args...>::value), - void>::type> - pair(_U1&& __x, _Args&&... __args) - : first(std::forward<_U1>(__x)), - second(std::forward<_Args>(__args)...) { } - - // Variadic constructor. The enable_if makes sure that the - // second argument isn't going to try to initialize a pointer - // from an integral type. However, T1 may be a pointer whose - // argument was a null pointer constant. - template::value, - void>::type> - pair(const _T1& __x, _Args&&... __args) - : first(__x), - second(std::forward<_Args>(__args)...) { } - - // Constructor typically used when T2 is a pointer and the - // second argument was a null pointer constant. The enable_if - // makes sure that the first argument isn't going to try to - // initialize a pointer from an integral type. - template::value, - void>::type> - pair(_U1&& __x, const _T2& __y) + // http://gcc.gnu.org/ml/libstdc++/2007-08/msg00052.html + template + pair(_U1&& __x, _Arg0&& __arg0, _Args&&... __args) : first(std::forward<_U1>(__x)), - second(__y) { } + second(std::forward<_Arg0>(__arg0), + std::forward<_Args>(__args)...) { } pair& operator=(pair&& __p) diff --git a/libstdc++-v3/testsuite/20_util/pair/moveable.cc b/libstdc++-v3/testsuite/20_util/pair/moveable.cc index 4e5c53583cd..cd5de4162eb 100644 --- a/libstdc++-v3/testsuite/20_util/pair/moveable.cc +++ b/libstdc++-v3/testsuite/20_util/pair/moveable.cc @@ -64,54 +64,9 @@ test2() r.second.size() == 2 && p.second.size() == 0); } -struct X { - explicit X(int, int) { } - -private: - X(const X&) = delete; -}; - -struct move_only { - move_only() { } - move_only(move_only&&) { } - -private: - move_only(const move_only&) = delete; -}; - -void -test3() -{ - int *ip = 0; - int X::*mp = 0; - std::pair p1(0, 0); - std::pair p2(ip, 0); - std::pair p3(0, ip); - std::pair p4(ip, ip); - - std::pair p5(0, 0); - std::pair p6(mp, 0); - std::pair p7(0, mp); - std::pair p8(mp, mp); - - std::pair p9(0, 1, 2); - std::pair p10(0, 1, 2); - std::pair p11(ip, 1, 2); - std::pair p12(mp, 1, 2); - - std::pair p13(0); - std::pair p14(0); - - std::pair p15(0, move_only()); - std::pair p16(0, move_only()); - std::pair p17(move_only(), 0); - std::pair p18(move_only(), 0); -} - int main() { test1(); test2(); - test3(); }