http://llvm.org/bugs/show_bug.cgi?id=11428

             Bug #: 11428
           Summary: errc, io_errc and future_errc constants should really
                    be scoped enums
           Product: libc++
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]
    Classification: Unclassified


Created attachment 7641
  --> http://llvm.org/bugs/attachment.cgi?id=7641
Patches for header files <system_error>, <future> and <ios>

The enumeration types errc, io_errc and future_errc are defined in the standard
with "enum class", but currently libc++ defines them as regular enums nested in
a struct. Although I understand that the struct+enum hack is more portable,
having scoped enumerations is essential for compiling even the following simple
code:

  void f(error_condition c)
  {
     if (c == errc::invalid_argument)
     { /* ... */ }
  }

that's because if errc::invalid_argument is a regular enum value it decays to
int and operator== becomes ambiguous. On the other hand, if it is a scoped enum
value, the only operator== available is the correct one, with signature:

  bool operator==(const error_condition& lhs, const error_condition& rhs)
noexcept;

(errc::invalid_argument being implicitly converted to error_condition because
of the is_error_condition_enum<> machinery).

I therefore suggest to use scoped enums wherever specified by the standard. I
am attaching patches that accomplish that unconditionally. A possible backward
compatible approach could be to add a __has_feature(cxx_strong_enums) check,
although it has to be noted that we already used scoped enumerations in
<condition_variable> without any check.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to