Commit 4661c8fd by Paolo Carlini Committed by Paolo Carlini

system_error (native_category): Remove.

2008-10-10  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/system_error (native_category): Remove.
	(posix_category): Add.
	(error_code::error_code(_ErrorCodeEnum, typename enable_if<>:type*):
	Fix _M_cat initialization.
	(error_code::operator=(_ErrorCodeEnum)): Assign _M_cat too.
	(error_condition::_M_cat, error_condtion::operator=
	(_ErrorConditionEnum)): Implement resolution of DR 804.
	(error_condition::error_condition(_ErrorConditionEnum, typename
	enable_if<>:type*): Fix.
	(error_condition::clear, error_condition::assign): Implement.
	(operator==, operator!=): Fix uglification of parameters.
	(make_error_code, make_error_condition): Define in namespace
	posix_error.
	(operator<<(basic_ostream<>&, const error_code&)): Define here.
	* include/std/ostream (operator<<(basic_ostream<>&,
	const error_code&)): Do not define here.
	* testsuite/19_diagnostics/error_condition/cons/1.cc: New.	
	* testsuite/19_diagnostics/error_condition/operators/bool.cc: Likewise.
	* testsuite/19_diagnostics/error_condition/operators/bool_neg.cc:
	Likewise.
	* testsuite/19_diagnostics/error_condition/operators/equal.cc:
	Likewise.
	* testsuite/19_diagnostics/error_condition/operators/not_equal.cc:
	Likewise.
	* testsuite/19_diagnostics/error_code/cons/1.cc: Tweak.
	* testsuite/19_diagnostics/error_category/cons/copy_neg.cc: Adjust
	dg-error line numbers.
	* testsuite/30_threads/unique_lock/locking/2.cc: Tweak.

	* testsuite/util/testsuite_error.h: Minor tweaks.
	* testsuite/util/testsuite_hooks.cc: Avoid uninitialized warning.

From-SVN: r141039
parent 87ad5081
2008-10-10 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/system_error (native_category): Remove.
(posix_category): Add.
(error_code::error_code(_ErrorCodeEnum, typename enable_if<>:type*):
Fix _M_cat initialization.
(error_code::operator=(_ErrorCodeEnum)): Assign _M_cat too.
(error_condition::_M_cat, error_condtion::operator=
(_ErrorConditionEnum)): Implement resolution of DR 804.
(error_condition::error_condition(_ErrorConditionEnum, typename
enable_if<>:type*): Fix.
(error_condition::clear, error_condition::assign): Implement.
(operator==, operator!=): Fix uglification of parameters.
(make_error_code, make_error_condition): Define in namespace
posix_error.
(operator<<(basic_ostream<>&, const error_code&)): Define here.
* include/std/ostream (operator<<(basic_ostream<>&,
const error_code&)): Do not define here.
* testsuite/19_diagnostics/error_condition/cons/1.cc: New.
* testsuite/19_diagnostics/error_condition/operators/bool.cc: Likewise.
* testsuite/19_diagnostics/error_condition/operators/bool_neg.cc:
Likewise.
* testsuite/19_diagnostics/error_condition/operators/equal.cc:
Likewise.
* testsuite/19_diagnostics/error_condition/operators/not_equal.cc:
Likewise.
* testsuite/19_diagnostics/error_code/cons/1.cc: Tweak.
* testsuite/19_diagnostics/error_category/cons/copy_neg.cc: Adjust
dg-error line numbers.
* testsuite/30_threads/unique_lock/locking/2.cc: Tweak.
* testsuite/util/testsuite_error.h: Minor tweaks.
* testsuite/util/testsuite_hooks.cc: Avoid uninitialized warning.
2008-10-10 Chris Fairles <cfairles@gcc.gnu.org> 2008-10-10 Chris Fairles <cfairles@gcc.gnu.org>
* testsuite/20_util/duration/cons/1.cc: Remove invalid check of * testsuite/20_util/duration/cons/1.cc: Remove invalid check of
......
...@@ -45,10 +45,6 @@ ...@@ -45,10 +45,6 @@
#include <ios> #include <ios>
#include <bits/ostream_insert.h> #include <bits/ostream_insert.h>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
# include <system_error>
#endif
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NAMESPACE(std)
// [27.6.2.1] Template class basic_ostream // [27.6.2.1] Template class basic_ostream
...@@ -535,13 +531,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -535,13 +531,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ return (__out << reinterpret_cast<const char*>(__s)); } { return (__out << reinterpret_cast<const char*>(__s)); }
//@} //@}
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, const error_code& __e)
{ return (__out << __e.category().name() << ':' << __e.value()); }
#endif
// [27.6.2.7] standard basic_ostream manipulators // [27.6.2.7] standard basic_ostream manipulators
/** /**
* @brief Write a newline and flush the stream. * @brief Write a newline and flush the stream.
......
...@@ -111,8 +111,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -111,8 +111,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const error_category& get_posix_category(); const error_category& get_posix_category();
const error_category& get_system_category(); const error_category& get_system_category();
static const error_category& posix_category = get_posix_category();
static const error_category& system_category = get_system_category(); static const error_category& system_category = get_system_category();
static const error_category& native_category = get_posix_category();
/// error_code /// error_code
// Implementation-specific error identification // Implementation-specific error identification
...@@ -127,7 +127,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -127,7 +127,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _ErrorCodeEnum> template<typename _ErrorCodeEnum>
error_code(_ErrorCodeEnum __e, error_code(_ErrorCodeEnum __e,
typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type* = 0) typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type* = 0)
: _M_value(__e), _M_cat(&system_category) : _M_value(__e), _M_cat(&posix_category)
{ } { }
void void
...@@ -144,10 +144,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -144,10 +144,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_M_cat = &system_category; _M_cat = &system_category;
} }
// DR 804.
template<typename _ErrorCodeEnum> template<typename _ErrorCodeEnum>
typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type& typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value,
error_code&>::type
operator=(_ErrorCodeEnum __e) operator=(_ErrorCodeEnum __e)
{ _M_value = __e; } {
_M_value = __e;
_M_cat = &posix_category;
return *this;
}
int int
value() const { return _M_value; } value() const { return _M_value; }
...@@ -172,55 +178,73 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -172,55 +178,73 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
operator __bool_type() const operator __bool_type() const
{ return _M_value != 0 ? &__not_bool_type : false; } { return _M_value != 0 ? &__not_bool_type : false; }
// DR 804.
private: private:
int _M_value; int _M_value;
const error_category* _M_cat; const error_category* _M_cat;
}; };
error_code
make_error_code(posix_error::posix_errno);
// 19.4.2.5 non-member functions // 19.4.2.5 non-member functions
bool operator<(const error_code& lhs, const error_code& rhs); inline bool
operator<(const error_code& __lhs, const error_code& __rhs)
{
return (__lhs.category() < __rhs.category()
|| (__lhs.category() == __rhs.category()
&& __lhs.value() < __rhs.value()));
}
template<typename charT, typename traits> template<typename _CharT, typename _Traits>
basic_ostream<charT,traits>& basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<charT, traits>& os, const error_code& __code); operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
{ return (__os << __e.category().name() << ':' << __e.value()); }
/// error_condition /// error_condition
// Portable error identification // Portable error identification
struct error_condition struct error_condition
{ {
error_condition() : _M_value(0), _M_cat(system_category) { } error_condition() : _M_value(0), _M_cat(&posix_category) { }
error_condition(int __v, const error_category& __cat) error_condition(int __v, const error_category& __cat)
: _M_value(__v), _M_cat(__cat) { } : _M_value(__v), _M_cat(&__cat) { }
template<typename _ErrorEnum> template<typename _ErrorConditionEnum>
error_condition(typename enable_if< error_condition(_ErrorConditionEnum __e,
is_error_condition_enum<_ErrorEnum>::value, typename enable_if<is_error_condition_enum
_ErrorEnum>::type __v) <_ErrorConditionEnum>::value>::type* = 0)
: _M_value(__v), _M_cat(system_category) { } : _M_value(__e), _M_cat(&posix_category) { }
void void
assign(int val, const error_category& cat); assign(int __v, const error_category& __cat)
{
_M_value = __v;
_M_cat = &__cat;
}
template<typename _ErrorEnum> // DR 804.
error_condition& template<typename _ErrorConditionEnum>
operator=(typename enable_if<is_error_condition_enum<_ErrorEnum>::value, typename enable_if<is_error_condition_enum
_ErrorEnum>::type __v) <_ErrorConditionEnum>::value, error_condition&>::type
{ _M_value = __v; } operator=(_ErrorConditionEnum __e)
{
_M_value = __e;
_M_cat = &posix_category;
return *this;
}
void void
clear(); clear()
{
_M_value = 0;
_M_cat = &posix_category;
}
// 19.4.3.4 observers // 19.4.3.4 observers
int int
value() const { return _M_value; } value() const { return _M_value; }
const error_category& const error_category&
category() const { return _M_cat; } category() const { return *_M_cat; }
string string
message() const message() const
...@@ -236,63 +260,75 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -236,63 +260,75 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
operator __bool_type() const operator __bool_type() const
{ return _M_value != 0 ? &__not_bool_type : false; } { return _M_value != 0 ? &__not_bool_type : false; }
// DR 804.
private: private:
int _M_value; int _M_value;
const error_category& _M_cat; const error_category* _M_cat;
}; };
error_condition
make_error_condition(posix_error::posix_errno);
// 19.4.3.5 non-member functions // 19.4.3.5 non-member functions
inline bool inline bool
operator<(const error_condition& lhs, const error_condition& rhs) operator<(const error_condition& __lhs, const error_condition& __rhs)
{ {
bool __t1 = lhs.category() < rhs.category(); return (__lhs.category() < __rhs.category()
bool __t2 = lhs.category() == rhs.category() && lhs.value() < rhs.value(); || (__lhs.category() == __rhs.category()
return __t1 || __t2; && __lhs.value() < __rhs.value()));
}
namespace posix_error
{
inline error_code
make_error_code(posix_errno __e)
{ return error_code(__e, posix_category); }
inline error_condition
make_error_condition(posix_errno __e)
{ return error_condition(__e, posix_category); }
} }
// 19.4.4 Comparison operators // 19.4.4 Comparison operators
inline bool inline bool
operator==(const error_code& lhs, const error_code& rhs) operator==(const error_code& __lhs, const error_code& __rhs)
{ return lhs.category() == rhs.category() && lhs.value() == rhs.value(); } { return (__lhs.category() == __rhs.category()
&& __lhs.value() == __rhs.value()); }
inline bool inline bool
operator==(const error_code& lhs, const error_condition& rhs) operator==(const error_code& __lhs, const error_condition& __rhs)
{ {
bool __t1 = lhs.category().equivalent(lhs.value(), rhs); return (__lhs.category().equivalent(__lhs.value(), __rhs)
bool __t2 = rhs.category().equivalent(lhs, rhs.value()); || __rhs.category().equivalent(__lhs, __rhs.value()));
return __t1 || __t2;
} }
inline bool inline bool
operator==(const error_condition& lhs, const error_code& rhs) operator==(const error_condition& __lhs, const error_code& __rhs)
{ {
bool __t1 = rhs.category().equivalent(rhs.value(), lhs); return (__rhs.category().equivalent(__rhs.value(), __lhs)
bool __t2 = lhs.category().equivalent(rhs, lhs.value()); || __lhs.category().equivalent(__rhs, __lhs.value()));
return __t1 || __t2;
} }
inline bool inline bool
operator==(const error_condition& lhs, const error_condition& rhs) operator==(const error_condition& __lhs, const error_condition& __rhs)
{ return lhs.category() == rhs.category() && lhs.value() == rhs.value(); } {
return (__lhs.category() == __rhs.category()
&& __lhs.value() == __rhs.value());
}
inline bool inline bool
operator!=(const error_code& lhs, const error_code& rhs) operator!=(const error_code& __lhs, const error_code& __rhs)
{ return !(lhs == rhs); } { return !(__lhs == __rhs); }
inline bool inline bool
operator!=(const error_code& lhs, const error_condition& rhs) operator!=(const error_code& __lhs, const error_condition& __rhs)
{ return !(lhs == rhs); } { return !(__lhs == __rhs); }
inline bool inline bool
operator!=(const error_condition& lhs, const error_code& rhs) operator!=(const error_condition& __lhs, const error_code& __rhs)
{ return !(lhs == rhs); } { return !(__lhs == __rhs); }
inline bool
operator!=(const error_condition& __lhs, const error_condition& __rhs)
{ return !(__lhs == __rhs); }
inline bool
operator!=(const error_condition& lhs, const error_condition& rhs)
{ return !(lhs == rhs); }
/// Thrown to indicate error code of underlying system. /// Thrown to indicate error code of underlying system.
class system_error : public std::runtime_error class system_error : public std::runtime_error
......
...@@ -34,6 +34,6 @@ int main() ...@@ -34,6 +34,6 @@ int main()
} }
// { dg-error "is private" "" { target *-*-* } 105 } // { dg-error "is private" "" { target *-*-* } 105 }
// { dg-error "within this context" "" { target *-*-* } 41 } // { dg-error "within this context" "" { target *-*-* } 40 }
// { dg-error "first required here" "" { target *-*-* } 31 } // { dg-error "first required here" "" { target *-*-* } 31 }
// { dg-excess-errors "copy constructor" } // { dg-excess-errors "copy constructor" }
...@@ -40,7 +40,7 @@ int main() ...@@ -40,7 +40,7 @@ int main()
// 3 // 3
std::error_code e3(std::posix_error::operation_not_supported); std::error_code e3(std::posix_error::operation_not_supported);
VERIFY( e3.value() == int(std::posix_error::operation_not_supported) ); VERIFY( e3.value() == int(std::posix_error::operation_not_supported) );
VERIFY( e3.category() == std::system_category ); VERIFY( e3.category() == std::posix_category );
return 0; return 0;
} }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <system_error>
#include <testsuite_error.h>
void test01()
{
bool test __attribute__((unused)) = true;
// 1
std::error_condition e1;
VERIFY( e1.value() == 0 );
VERIFY( e1.category() == std::posix_category );
// 2
const __gnu_test::test_category cat;
std::error_condition e2(e1.value(), cat);
VERIFY( e2.value() == e1.value() );
VERIFY( e2.category() == cat );
// 3
std::error_condition e3(std::posix_error::operation_not_supported);
VERIFY( e3.value() == int(std::posix_error::operation_not_supported) );
VERIFY( e3.category() == std::posix_category );
}
int main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <system_error>
#include <testsuite_hooks.h>
// unspecified bool operator positive tests
void test01()
{
bool test __attribute__((unused)) = true;
// 1
std::error_condition e1;
if (e1)
{
VERIFY( false );
}
// 2
std::error_condition e2(std::posix_error::operation_not_supported);
if (e2)
{
VERIFY( true );
}
}
int main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <system_error>
#include <testsuite_hooks.h>
int test01()
{
std::error_condition e;
int i = e;
return i;
}
// { dg-error "invalid conversion" "" { target *-*-* } 28 }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <system_error>
#include <testsuite_error.h>
// unspecified bool operator positive tests
void test01()
{
bool test __attribute__((unused)) = true;
std::error_condition e1;
std::error_condition e2(std::posix_error::operation_not_supported);
VERIFY( e1 == e1 );
VERIFY( !(e1 == e2) );
const __gnu_test::test_category cat;
std::error_condition e3(e2.value(), cat);
VERIFY( !(e2 == e3) );
}
int main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <system_error>
#include <testsuite_error.h>
// unspecified bool operator positive tests
void test01()
{
bool test __attribute__((unused)) = true;
std::error_condition e1;
std::error_condition e2(std::posix_error::operation_not_supported);
VERIFY( !(e1 != e1) );
VERIFY( e1 != e2 );
const __gnu_test::test_category cat;
std::error_condition e3(e2.value(), cat);
VERIFY( e2 != e3 );
}
int main()
{
test01();
return 0;
}
...@@ -51,9 +51,10 @@ void test01() ...@@ -51,9 +51,10 @@ void test01()
{ {
l.lock(); l.lock();
} }
catch (std::system_error const& ex) catch (const std::system_error& ex)
{ {
VERIFY( ex.code() == std::posix_error::operation_not_permitted ); VERIFY( ex.code() == std::error_code(
std::posix_error::operation_not_permitted) );
} }
catch (...) catch (...)
{ {
...@@ -89,7 +90,8 @@ void test02() ...@@ -89,7 +90,8 @@ void test02()
} }
catch (const std::system_error& ex) catch (const std::system_error& ex)
{ {
VERIFY( ex.code() == std::posix_error::resource_deadlock_would_occur ); VERIFY( ex.code() == std::error_code(
std::posix_error::resource_deadlock_would_occur) );
} }
catch (...) catch (...)
{ {
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
// invalidate any other reasons why the executable file might be covered by // invalidate any other reasons why the executable file might be covered by
// the GNU General Public License. // the GNU General Public License.
#include <string>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#ifndef _TESTSUITE_ERROR_H #ifndef _TESTSUITE_ERROR_H
...@@ -35,8 +36,6 @@ ...@@ -35,8 +36,6 @@
namespace __gnu_test namespace __gnu_test
{ {
using std::string;
struct test_category : public std::error_category struct test_category : public std::error_category
{ {
virtual const char* virtual const char*
...@@ -46,10 +45,9 @@ namespace __gnu_test ...@@ -46,10 +45,9 @@ namespace __gnu_test
return s; return s;
} }
virtual string virtual std::string
message(int) const message(int) const
{ return string("message to be determined"); } { return std::string("message to be determined"); }
}; };
struct test_derived_category : public test_category struct test_derived_category : public test_category
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Utility subroutines for the C++ library testsuite. // Utility subroutines for the C++ library testsuite.
// //
// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 // Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
// Free Software Foundation, Inc. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -283,6 +283,7 @@ namespace __gnu_test ...@@ -283,6 +283,7 @@ namespace __gnu_test
{ {
#ifdef _GLIBCXX_SYSV_SEM #ifdef _GLIBCXX_SYSV_SEM
union semun val; union semun val;
val.val = 0; // Avoid uninitialized variable warning.
// Destroy the semaphore set only in the process that created it. // Destroy the semaphore set only in the process that created it.
if (pid_ == getpid()) if (pid_ == getpid())
semctl(sem_set_, 0, IPC_RMID, val); semctl(sem_set_, 0, IPC_RMID, val);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment