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@DU?$char_traits@D@” _LIBCPP_ABI_NAMESPACE_STR “@std@@@12@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 (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

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

Thanks, that explains it!

Louis