This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] libstdc++/39880/39881/39882
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sat, 25 Apr 2009 21:04:09 +0200
- Subject: [v3] libstdc++/39880/39881/39882
Hi,
tested x86_64-linux multilib, committed to mainline (will probably go in
4_4-branch too)
Paolo.
////////////////
2009-04-25 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/39880
PR libstdc++/39881
PR libstdc++/39882
* include/std/system_error (is_error_code_enum<errc>): Remove.
(error_condition<>::error_condition(_ErrorCodeEnum,)
error_condition<>::operator=(_ErrorCodeEnum)): Use make_error_condition.
(error_code<>::error_code(_ErrorCodeEnum,),
error_code<>::operator=(_ErrorCodeEnum)): Use make_error_code.
* testsuite/19_diagnostics/system_error/39880.cc: New.
* testsuite/19_diagnostics/error_condition/modifiers/39881.cc:
Likewise.
* testsuite/19_diagnostics/error_condition/cons/39881.cc: Likewise.
* testsuite/19_diagnostics/error_code/modifiers/39882.cc: Likewise.
* testsuite/19_diagnostics/error_code/cons/39882.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc:
Adjust.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc:
Likewise.
* testsuite/19_diagnostics/error_code/cons/1.cc: Likewise.
* testsuite/19_diagnostics/error_code/operators/bool.cc: Likewise.
* testsuite/19_diagnostics/error_code/operators/equal.cc: Likewise.
* testsuite/19_diagnostics/error_code/operators/not_equal.cc:
Likewise.
* testsuite/19_diagnostics/error_category/cons/copy_neg.cc: Likewise.
* testsuite/19_diagnostics/system_error/cons-1.cc: Likewise.
* testsuite/19_diagnostics/system_error/what-4.cc: Likewise.
* testsuite/30_threads/unique_lock/locking/2.cc: Likewise.
Index: include/std/system_error
===================================================================
--- include/std/system_error (revision 146764)
+++ include/std/system_error (working copy)
@@ -51,10 +51,6 @@
template<typename _Tp>
struct is_error_code_enum : public false_type { };
- template<>
- struct is_error_code_enum<errc>
- : public true_type { };
-
/// is_error_condition_enum
template<typename _Tp>
struct is_error_condition_enum : public false_type { };
@@ -108,12 +104,14 @@
_GLIBCXX_CONST const error_category& system_category() throw ();
_GLIBCXX_CONST const error_category& generic_category() throw ();
+ error_code make_error_code(errc);
+
/// error_code
// Implementation-specific error identification
struct error_code
{
error_code()
- : _M_value(0), _M_cat(&system_category()) { }
+ : _M_value(0), _M_cat(&system_category()) { }
error_code(int __v, const error_category& __cat)
: _M_value(__v), _M_cat(&__cat) { }
@@ -121,8 +119,7 @@
template<typename _ErrorCodeEnum>
error_code(_ErrorCodeEnum __e,
typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type* = 0)
- : _M_value(static_cast<int>(__e)), _M_cat(&generic_category())
- { }
+ { *this = make_error_code(__e); }
void
assign(int __v, const error_category& __cat)
@@ -140,10 +137,7 @@
typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value,
error_code&>::type
operator=(_ErrorCodeEnum __e)
- {
- assign(static_cast<int>(__e), generic_category());
- return *this;
- }
+ { return *this = make_error_code(__e); }
int
value() const { return _M_value; }
@@ -192,12 +186,14 @@
operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
{ return (__os << __e.category().name() << ':' << __e.value()); }
+ error_condition make_error_condition(errc);
/// error_condition
// Portable error identification
struct error_condition
{
- error_condition() : _M_value(0), _M_cat(&generic_category()) { }
+ error_condition()
+ : _M_value(0), _M_cat(&generic_category()) { }
error_condition(int __v, const error_category& __cat)
: _M_value(__v), _M_cat(&__cat) { }
@@ -206,7 +202,7 @@
error_condition(_ErrorConditionEnum __e,
typename enable_if<is_error_condition_enum
<_ErrorConditionEnum>::value>::type* = 0)
- : _M_value(static_cast<int>(__e)), _M_cat(&generic_category()) { }
+ { *this = make_error_condition(__e); }
void
assign(int __v, const error_category& __cat)
@@ -220,10 +216,7 @@
typename enable_if<is_error_condition_enum
<_ErrorConditionEnum>::value, error_condition&>::type
operator=(_ErrorConditionEnum __e)
- {
- assign(static_cast<int>(__e), generic_category());
- return *this;
- }
+ { return *this = make_error_condition(__e); }
void
clear()
Index: testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc
===================================================================
--- testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc (revision 146762)
+++ testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc (working copy)
@@ -1,6 +1,6 @@
// { dg-options "-std=gnu++0x" }
-// Copyright (C) 2007, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009 Free Software Foundation
//
// 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
@@ -32,7 +32,7 @@
wchar_t buf[64];
error_code e1;
- error_code e2(errc::bad_address);
+ error_code e2(make_error_code(errc::bad_address));
wstring s, s1, s2;
{
Index: testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc
===================================================================
--- testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc (revision 146762)
+++ testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc (working copy)
@@ -32,7 +32,7 @@
char buf[64];
error_code e1;
- error_code e2(errc::bad_address);
+ error_code e2(make_error_code(errc::bad_address));
string s, s1, s2;
{
Index: testsuite/19_diagnostics/error_condition/modifiers/39881.cc
===================================================================
--- testsuite/19_diagnostics/error_condition/modifiers/39881.cc (revision 0)
+++ testsuite/19_diagnostics/error_condition/modifiers/39881.cc (revision 0)
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 <system_error>
+#include <testsuite_hooks.h>
+
+enum my_errc { my_err = 0 };
+
+class my_error_category_impl
+: public std::error_category
+{
+public:
+ const char* name() const { return ""; }
+ std::string message(int) const { return ""; }
+} my_error_category_instance;
+
+std::error_condition
+make_error_condition(my_errc e)
+{
+ return std::error_condition(static_cast<int>(e),
+ my_error_category_instance);
+}
+
+namespace std
+{
+ template<>
+ struct is_error_condition_enum<my_errc>
+ : public true_type { };
+}
+
+// libstdc++/39881
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::error_condition ec2;
+ ec2 = my_err;
+ VERIFY( ec2 == make_error_condition(my_err) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/19_diagnostics/error_condition/cons/39881.cc
===================================================================
--- testsuite/19_diagnostics/error_condition/cons/39881.cc (revision 0)
+++ testsuite/19_diagnostics/error_condition/cons/39881.cc (revision 0)
@@ -0,0 +1,60 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 <system_error>
+#include <testsuite_hooks.h>
+
+enum my_errc { my_err = 0 };
+
+class my_error_category_impl
+: public std::error_category
+{
+public:
+ const char* name() const { return ""; }
+ std::string message(int) const { return ""; }
+} my_error_category_instance;
+
+std::error_condition
+make_error_condition(my_errc e)
+{
+ return std::error_condition(static_cast<int>(e),
+ my_error_category_instance);
+}
+
+namespace std
+{
+ template<>
+ struct is_error_condition_enum<my_errc>
+ : public true_type { };
+}
+
+// libstdc++/39881
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::error_condition ec1(my_err);
+ VERIFY( ec1 == make_error_condition(my_err) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/19_diagnostics/error_code/modifiers/39882.cc
===================================================================
--- testsuite/19_diagnostics/error_code/modifiers/39882.cc (revision 0)
+++ testsuite/19_diagnostics/error_code/modifiers/39882.cc (revision 0)
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 <system_error>
+#include <testsuite_hooks.h>
+
+enum my_errc { my_err = 0 };
+
+class my_error_category_impl
+: public std::error_category
+{
+public:
+ const char* name() const { return ""; }
+ std::string message(int) const { return ""; }
+} my_error_category_instance;
+
+std::error_code
+make_error_code(my_errc e)
+{
+ return std::error_code(static_cast<int>(e),
+ my_error_category_instance);
+}
+
+namespace std
+{
+ template<>
+ struct is_error_code_enum<my_errc>
+ : public true_type {};
+}
+
+// libstdc++/39882
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::error_code ec2;
+ ec2 = my_err;
+ VERIFY( ec2 == make_error_code(my_err) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/19_diagnostics/error_code/cons/39882.cc
===================================================================
--- testsuite/19_diagnostics/error_code/cons/39882.cc (revision 0)
+++ testsuite/19_diagnostics/error_code/cons/39882.cc (revision 0)
@@ -0,0 +1,60 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 <system_error>
+#include <testsuite_hooks.h>
+
+enum my_errc { my_err = 0 };
+
+class my_error_category_impl
+: public std::error_category
+{
+public:
+ const char* name() const { return ""; }
+ std::string message(int) const { return ""; }
+} my_error_category_instance;
+
+std::error_code
+make_error_code(my_errc e)
+{
+ return std::error_code(static_cast<int>(e),
+ my_error_category_instance);
+}
+
+namespace std
+{
+ template<>
+ struct is_error_code_enum<my_errc>
+ : public true_type {};
+}
+
+// libstdc++/39882
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::error_code ec1(my_err);
+ VERIFY( ec1 == make_error_code(my_err) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/19_diagnostics/error_code/cons/1.cc
===================================================================
--- testsuite/19_diagnostics/error_code/cons/1.cc (revision 146762)
+++ testsuite/19_diagnostics/error_code/cons/1.cc (working copy)
@@ -37,7 +37,7 @@
VERIFY( e2.category() == cat );
// 3
- std::error_code e3(std::errc::operation_not_supported);
+ std::error_code e3(std::make_error_code(std::errc::operation_not_supported));
VERIFY( e3.value() == int(std::errc::operation_not_supported) );
VERIFY( e3.category() == std::generic_category() );
Index: testsuite/19_diagnostics/error_code/operators/bool.cc
===================================================================
--- testsuite/19_diagnostics/error_code/operators/bool.cc (revision 146762)
+++ testsuite/19_diagnostics/error_code/operators/bool.cc (working copy)
@@ -34,7 +34,7 @@
}
// 2
- std::error_code e2(std::errc::operation_not_supported);
+ std::error_code e2(std::make_error_code(std::errc::operation_not_supported));
if (e2)
{
VERIFY( true );
Index: testsuite/19_diagnostics/error_code/operators/equal.cc
===================================================================
--- testsuite/19_diagnostics/error_code/operators/equal.cc (revision 146762)
+++ testsuite/19_diagnostics/error_code/operators/equal.cc (working copy)
@@ -27,7 +27,7 @@
bool test __attribute__((unused)) = true;
std::error_code e1;
- std::error_code e2(std::errc::operation_not_supported);
+ std::error_code e2(std::make_error_code(std::errc::operation_not_supported));
VERIFY( e1 == e1 );
VERIFY( !(e1 == e2) );
Index: testsuite/19_diagnostics/error_code/operators/not_equal.cc
===================================================================
--- testsuite/19_diagnostics/error_code/operators/not_equal.cc (revision 146762)
+++ testsuite/19_diagnostics/error_code/operators/not_equal.cc (working copy)
@@ -27,7 +27,7 @@
bool test __attribute__((unused)) = true;
std::error_code e1;
- std::error_code e2(std::errc::operation_not_supported);
+ std::error_code e2(std::make_error_code(std::errc::operation_not_supported));
VERIFY( !(e1 != e1) );
VERIFY( e1 != e2 );
Index: testsuite/19_diagnostics/error_category/cons/copy_neg.cc
===================================================================
--- testsuite/19_diagnostics/error_category/cons/copy_neg.cc (revision 146762)
+++ testsuite/19_diagnostics/error_category/cons/copy_neg.cc (working copy)
@@ -32,7 +32,7 @@
return 0;
}
-// { dg-error "deleted function" "" { target *-*-* } 76 }
+// { dg-error "deleted function" "" { target *-*-* } 72 }
// { dg-error "used here" "" { target *-*-* } 31 }
// { dg-error "first required here" "" { target *-*-* } 30 }
// { dg-excess-errors "copy constructor" }
Index: testsuite/19_diagnostics/system_error/39880.cc
===================================================================
--- testsuite/19_diagnostics/system_error/39880.cc (revision 0)
+++ testsuite/19_diagnostics/system_error/39880.cc (revision 0)
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2009 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 <system_error>
+
+// libstdc++/39880
+void test01()
+{
+ std::error_code ec;
+ if (ec == std::errc::not_supported)
+ { }
+}
Index: testsuite/19_diagnostics/system_error/cons-1.cc
===================================================================
--- testsuite/19_diagnostics/system_error/cons-1.cc (revision 146762)
+++ testsuite/19_diagnostics/system_error/cons-1.cc (working copy)
@@ -26,7 +26,8 @@
{
bool test __attribute__((unused)) = true;
const std::string s("too late: boulangerie out of pain au raisin");
- const std::error_code e(std::errc::operation_not_supported);
+ const std::error_code
+ e(std::make_error_code(std::errc::operation_not_supported));
// 1
{
Index: testsuite/19_diagnostics/system_error/what-4.cc
===================================================================
--- testsuite/19_diagnostics/system_error/what-4.cc (revision 146762)
+++ testsuite/19_diagnostics/system_error/what-4.cc (working copy)
@@ -31,7 +31,8 @@
bool test __attribute__((unused)) = true;
std::string s("after nine thirty, this request cannot be met");
- std::system_error obj = std::system_error(std::errc::invalid_argument, s);
+ std::system_error obj =
+ std::system_error(std::make_error_code(std::errc::invalid_argument), s);
std::string s1(obj.what());
std::string s2(obj.what());
VERIFY( s1 == s2 );
Index: testsuite/30_threads/unique_lock/locking/2.cc
===================================================================
--- testsuite/30_threads/unique_lock/locking/2.cc (revision 146762)
+++ testsuite/30_threads/unique_lock/locking/2.cc (working copy)
@@ -44,7 +44,8 @@
}
catch (const std::system_error& ex)
{
- VERIFY( ex.code() == std::error_code(std::errc::operation_not_permitted) );
+ VERIFY( ex.code() == std::make_error_code
+ (std::errc::operation_not_permitted) );
}
catch (...)
{
@@ -80,8 +81,8 @@
}
catch (const std::system_error& ex)
{
- VERIFY( ex.code() == std::error_code(
- std::errc::resource_deadlock_would_occur) );
+ VERIFY( ex.code() == std::make_error_code
+ (std::errc::resource_deadlock_would_occur) );
}
catch (...)
{