[cfe-dev] std::error_category not extensible?

Gordon Henriksen gordonhenriksen at me.com
Sun Dec 16 20:14:45 PST 2012


On 2012-12-16, at 18:29, Gordon Henriksen wrote:

> We have a reasonably large body of code using std::error_category subclasses on Visual C++. With libc++, error_category::error_category() is private, preventing this code from porting. Was there a late decision by the standards committee to redact system_error extensibility...?

I found these references. This is a bug in the standard, which libc++ faithfully
reproduced.

  http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-September/024528.html
  http://cplusplus.github.com/LWG/lwg-active.html#2145

I'm trying the below device as a workaround, though it's quite troublesome to
guarantee that <system_error> is not included before my wrapper, similar to
the __STDC_LIMIT_MACROS mistake.

-- Gordon


#ifndef CARBONITE_COMPAT_SYSTEM_ERROR_INCLUDED
#define CARBONITE_COMPAT_SYSTEM_ERROR_INCLUDED

#if defined(_LIBCPP_SYSTEM_ERROR) || \
    defined(_msvc_include_guard_tbd) || \
    defined(libstdcxx_include_guard_tbd)
#  error Include "carbonite/compat/system_error" before <system_error>.
#endif

#include "carbonite/compat/Compiler.h"
#if CARB_TOOLCHAIN_CPP11 || CARB_TOOLCHAIN_VC2010
// This is a gross workaround, so limit its scope. _LIBCPP_VERSION 1001 shipped
// with Xcode 4.5.2, which requires the hack.
#  if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 1001
//   std::error_category's constructor is inaccessible per the letter of a bug
//   in the standard. http://cplusplus.github.com/LWG/lwg-active.html#2145
#    define private protected
#  endif
#  include <system_error>
#  undef private
#endif /* CARB_TOOLCHAIN_CPP11 || CARB_TOOLCHAIN_VC2010 */

...

#endif /* !defined(CARBONITE_COMPAT_SYSTEM_ERROR_INCLUDED) */



More information about the cfe-dev mailing list