Index: docs/DesignDocs/VisibilityMacros.rst =================================================================== --- docs/DesignDocs/VisibilityMacros.rst +++ docs/DesignDocs/VisibilityMacros.rst @@ -210,6 +210,11 @@ available. This is an internal macro used by other visibility macros, and it should not be used directly. +**_LIBCPP_REFSTRING_TYPE_VISIBILITY** + When targeting the MSVC ABI, mark a type's typeinfo, vtable and members as + having default visibility. Otherwise, mark them as hidden so they will not be + exported from shared libraries. Used specifically for `__libcpp_refstring`. + Links ===== Index: include/__config =================================================================== --- include/__config +++ include/__config @@ -999,6 +999,15 @@ # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION #endif +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +# define _LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS +# define _LIBCPP_REFSTRING_TYPE_VISIBILITY _LIBCPP_TYPE_VIS +# define _LIBCPP_REFSTRING_INLINE +#else +# define _LIBCPP_REFSTRING_TYPE_VISIBILITY _LIBCPP_HIDDEN +# define _LIBCPP_REFSTRING_INLINE inline +#endif + #if defined(__APPLE__) # if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \ defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) Index: include/stdexcept =================================================================== --- include/stdexcept +++ include/stdexcept @@ -54,7 +54,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -class _LIBCPP_HIDDEN __libcpp_refstring +class _LIBCPP_REFSTRING_TYPE_VISIBILITY __libcpp_refstring { const char* __imp_; @@ -80,12 +80,16 @@ _VSTD::__libcpp_refstring __imp_; public: explicit logic_error(const string&); +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) + _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __msg) : __imp_(__msg) {} +#else explicit logic_error(const char*); logic_error(const logic_error&) _NOEXCEPT; logic_error& operator=(const logic_error&) _NOEXCEPT; virtual ~logic_error() _NOEXCEPT; +#endif virtual const char* what() const _NOEXCEPT; }; @@ -97,12 +101,16 @@ _VSTD::__libcpp_refstring __imp_; public: explicit runtime_error(const string&); +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) + _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __msg) : __imp_(__msg) {} +#else explicit runtime_error(const char*); runtime_error(const runtime_error&) _NOEXCEPT; runtime_error& operator=(const runtime_error&) _NOEXCEPT; virtual ~runtime_error() _NOEXCEPT; +#endif virtual const char* what() const _NOEXCEPT; }; @@ -114,7 +122,9 @@ _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) virtual ~domain_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI invalid_argument @@ -124,7 +134,9 @@ _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) virtual ~invalid_argument() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI length_error @@ -134,7 +146,9 @@ _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) virtual ~length_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI out_of_range @@ -144,7 +158,9 @@ _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) virtual ~out_of_range() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI range_error @@ -154,7 +170,9 @@ _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) virtual ~range_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI overflow_error @@ -164,7 +182,9 @@ _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) virtual ~overflow_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI underflow_error @@ -174,7 +194,9 @@ _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) virtual ~underflow_error() _NOEXCEPT; +#endif }; } // std Index: src/include/refstring.h =================================================================== --- src/include/refstring.h +++ src/include/refstring.h @@ -66,7 +66,7 @@ using namespace __refstring_imp; -inline +_LIBCPP_REFSTRING_INLINE __libcpp_refstring::__libcpp_refstring(const char* msg) { std::size_t len = strlen(msg); _Rep_base* rep = static_cast<_Rep_base *>(::operator new(sizeof(*rep) + len + 1)); @@ -78,7 +78,7 @@ __imp_ = data; } -inline +_LIBCPP_REFSTRING_INLINE __libcpp_refstring::__libcpp_refstring(const __libcpp_refstring &s) _NOEXCEPT : __imp_(s.__imp_) { @@ -86,7 +86,7 @@ __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1); } -inline +_LIBCPP_REFSTRING_INLINE __libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) _NOEXCEPT { bool adjust_old_count = __uses_refcount(); struct _Rep_base *old_rep = rep_from_data(__imp_); @@ -103,7 +103,7 @@ return *this; } -inline +_LIBCPP_REFSTRING_INLINE __libcpp_refstring::~__libcpp_refstring() { if (__uses_refcount()) { _Rep_base* rep = rep_from_data(__imp_); @@ -113,7 +113,7 @@ } } -inline +_LIBCPP_REFSTRING_INLINE bool __libcpp_refstring::__uses_refcount() const { #ifdef __APPLE__ return __imp_ != get_gcc_empty_string_storage(); Index: src/stdexcept.cpp =================================================================== --- src/stdexcept.cpp +++ src/stdexcept.cpp @@ -28,6 +28,7 @@ { } +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) logic_error::logic_error(const char* msg) : __imp_(msg) { } @@ -42,11 +43,13 @@ __imp_ = le.__imp_; return *this; } +#endif runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str()) { } +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) runtime_error::runtime_error(const char* msg) : __imp_(msg) { } @@ -62,6 +65,7 @@ __imp_ = le.__imp_; return *this; } +#endif #if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX) @@ -77,7 +81,7 @@ return __imp_.c_str(); } -#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) +#if !defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) logic_error::~logic_error() _NOEXCEPT {} domain_error::~domain_error() _NOEXCEPT {}