This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/39882] New: error_code constructor and assignment postconditions not met
- From: "chris_kohlhoff at internet-mail dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Apr 2009 09:50:33 -0000
- Subject: [Bug libstdc++/39882] New: error_code constructor and assignment postconditions not met
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This is the same problem as 39881, but for error_code.
The constructor and assignment operator that take a ErrorCodeEnum both have the
postcondition: *this == make_error_code(e). The system_error header as of 4.4.0
does not meet this postcondition, because it always initialises the error_code
using the generic_category().
The following code:
#include <system_error>
#include <iostream>
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 {};
}
int main()
{
std::error_code ec1(my_err);
if (ec1 == make_error_code(my_err))
std::cout << "postcondition met\n";
else
std::cout << "postcondition not met\n";
std::error_code ec2;
ec2 = my_err;
if (ec2 == make_error_code(my_err))
std::cout << "postcondition met\n";
else
std::cout << "postcondition not met\n";
}
Currently outputs:
postcondition not met
postcondition not met
when it should output:
postcondition met
postcondition met
--
Summary: error_code constructor and assignment postconditions not
met
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: chris_kohlhoff at internet-mail dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39882