[LLVMbugs] [Bug 11428] New: errc, io_errc and future_errc constants should really be scoped enums

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Nov 24 00:57:13 PST 2011


             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: hhinnant at apple.com
        ReportedBy: ganesh at barbati.net
                CC: llvmbugs at cs.uiuc.edu
    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

  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)

(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.

More information about the llvm-bugs mailing list