[cfe-dev] std::use_facet<std::ctype<char>> crashes on linux

Eli Friedman eli.friedman at gmail.com
Mon Aug 19 14:12:05 PDT 2013


On Mon, Aug 19, 2013 at 9:36 AM, Howard Hinnant <hhinnant at apple.com> wrote:

> Ok, I've seen this one before:
>
> ------------------------------------------------------------------------
> r160785 | hhinnant | 2012-07-26 12:14:37 -0400 (Thu, 26 Jul 2012) | 1 line
>
> locale::id really needs to be constructed at compile time.
> ------------------------------------------------------------------------
> Index: include/__locale
> ===================================================================
> --- include/__locale    (revision 160784)
> +++ include/__locale    (revision 160785)
> @@ -119,7 +119,7 @@
>
>      static int32_t __next_id;
>  public:
> -    _LIBCPP_INLINE_VISIBILITY id() {}
> +    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
>  private:
>      void __init();
>      void operator=(const id&); // = delete;
>
> The old design was to count on the loader to zero out the id, and if the
> ctor happened afterwards, it did nothing.  This was replaced with an
> attempt to force the construction at compile time.  I don't recall exactly
> why the old design started failing, but it did, at about the same time
> constexpr was introduced into clang.
>
> Unfortunately we can not apply constexpr to:
>
> locale::id ctype<char>::id;
>
> because it isn't truly const.  It gets modified the first time its __get()
> function gets called.
>

A static member where the called constructor constructor is constexpr is
guaranteed to be constructed at compile-time by the C++11 standard.  You
shouldn't need to apple constexpr to the variable itself.

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130819/af9141bf/attachment.html>


More information about the cfe-dev mailing list