This is the mail archive of the gcc-bugs@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]

[Bug libstdc++/39881] New: error_condition constructor and assignment postconditions not met


The constructor and assignment operator that take a ErrorConditionEnum both
have the postcondition: *this == make_error_condition(e). The system_error
header as of 4.4.0 does not meet this postcondition, because it always
initialises the error_condition 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_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 {};
  }

  int main()
  {
    std::error_condition ec1(my_err);
    if (ec1 == make_error_condition(my_err))
      std::cout << "postcondition met\n";
    else
      std::cout << "postcondition not met\n";

    std::error_condition ec2;
    ec2 = my_err;
    if (ec2 == make_error_condition(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_condition 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=39881


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