[libcxx-dev] Question on how libc++ defines cin and other streams

Shoaib Meenai via libcxx-dev libcxx-dev at lists.llvm.org
Wed Nov 28 12:40:28 PST 2018


We have a mangling mismatch between the declaration and definitions of the streams otherwise. https://reviews.llvm.org/D23378 explains it further.

From: libcxx-dev <libcxx-dev-bounces at lists.llvm.org> on behalf of Louis Dionne via libcxx-dev <libcxx-dev at lists.llvm.org>
Reply-To: Louis Dionne <ldionne at apple.com>
Date: Wednesday, November 28, 2018 at 8:36 AM
To: "libcxx-dev at lists.llvm.org" <libcxx-dev at lists.llvm.org>
Subject: [libcxx-dev] Question on how libc++ defines cin and other streams

Hi,

In src/iostream.cpp, I can find the following beautiful declarations:

    _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
    #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
    __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream at DU?$char_traits at D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12 at A")
    #endif
    ;

    // etc...

And then we have this a little lower in src/iostream.cpp:

    _LIBCPP_HIDDEN ios_base::Init __start_std_streams;
    ios_base::Init::Init() {
        istream* cin_ptr  = ::new(cin)  istream(::new(__cin)  __stdinbuf <char>(stdin, &mb_cin));
        // ...
    }

I understand we're basically allocating a char array and then placement newing the stream into it during static initialization. However, why is that dance necessary with Clang-on-Windows?

Thanks,
Louis

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20181128/564807f8/attachment-0001.html>


More information about the libcxx-dev mailing list