Index: docs/DesignDocs/VisibilityMacros.rst =================================================================== --- docs/DesignDocs/VisibilityMacros.rst +++ docs/DesignDocs/VisibilityMacros.rst @@ -210,6 +210,17 @@ 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`. + +**_LIBCPP_STDEXCEPT_INLINE_VISIBILITY** + When targeting the MSVC ABI, mark a function as not being part of the ABI of + any final linked image that uses it. On all other platforms, this macro has + an empty definition. Used only for `std::logic_error`, `std::runtime_error`, + and their subclasses. + Links ===== Index: include/__config =================================================================== --- include/__config +++ include/__config @@ -999,6 +999,17 @@ # 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_STDEXCEPT_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY +# define _LIBCPP_REFSTRING_TYPE_VISIBILITY _LIBCPP_TYPE_VIS +# define _LIBCPP_REFSTRING_INLINE +#else +# define _LIBCPP_REFSTRING_TYPE_VISIBILITY _LIBCPP_HIDDEN +# define _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +# 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,16 +80,33 @@ _VSTD::__libcpp_refstring __imp_; public: explicit logic_error(const string&); - explicit logic_error(const char*); + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY explicit logic_error(const char*); - logic_error(const logic_error&) _NOEXCEPT; - logic_error& operator=(const logic_error&) _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY logic_error(const logic_error&) _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY logic_error& operator=(const logic_error&) _NOEXCEPT; - virtual ~logic_error() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~logic_error() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +logic_error::logic_error(const char* msg) : __imp_(msg) {} + +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_) {} + +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +logic_error& logic_error::operator=(const logic_error& le) _NOEXCEPT { + __imp_ = le.__imp_; + return *this; +} + +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +logic_error::~logic_error() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI runtime_error : public exception { @@ -97,16 +114,33 @@ _VSTD::__libcpp_refstring __imp_; public: explicit runtime_error(const string&); - explicit runtime_error(const char*); + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY explicit runtime_error(const char*); - runtime_error(const runtime_error&) _NOEXCEPT; - runtime_error& operator=(const runtime_error&) _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY runtime_error(const runtime_error&) _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY runtime_error& operator=(const runtime_error&) _NOEXCEPT; - virtual ~runtime_error() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~runtime_error() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +runtime_error::runtime_error(const char* msg) : __imp_(msg) {} + +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +runtime_error::runtime_error(const runtime_error& re) _NOEXCEPT : __imp_(re.__imp_) {} + +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +runtime_error& runtime_error::operator=(const runtime_error& re) _NOEXCEPT { + __imp_ = re.__imp_; + return *this; +} + +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +runtime_error::~runtime_error() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI domain_error : public logic_error { @@ -114,9 +148,14 @@ _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} - virtual ~domain_error() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~domain_error() _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +domain_error::~domain_error() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI invalid_argument : public logic_error { @@ -124,9 +163,14 @@ _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} - virtual ~invalid_argument() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~invalid_argument() _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +invalid_argument::~invalid_argument() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI length_error : public logic_error { @@ -134,9 +178,14 @@ _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} - virtual ~length_error() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~length_error() _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +length_error::~length_error() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI out_of_range : public logic_error { @@ -144,9 +193,14 @@ _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) {} - virtual ~out_of_range() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~out_of_range() _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +out_of_range::~out_of_range() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI range_error : public runtime_error { @@ -154,9 +208,14 @@ _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} - virtual ~range_error() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~range_error() _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +range_error::~range_error() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI overflow_error : public runtime_error { @@ -164,9 +223,14 @@ _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} - virtual ~overflow_error() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~overflow_error() _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +overflow_error::~overflow_error() _NOEXCEPT {} +#endif + class _LIBCPP_EXCEPTION_ABI underflow_error : public runtime_error { @@ -174,9 +238,14 @@ _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} - virtual ~underflow_error() _NOEXCEPT; + _LIBCPP_STDEXCEPT_INLINE_VISIBILITY virtual ~underflow_error() _NOEXCEPT; }; +#if defined(_LIBCPP_ABI_INLINE_STDEXCEPT_DEFINITIONS) +inline _LIBCPP_STDEXCEPT_INLINE_VISIBILITY +underflow_error::~underflow_error() _NOEXCEPT {} +#endif + } // std _LIBCPP_BEGIN_NAMESPACE_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,26 +43,29 @@ __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) { } -runtime_error::runtime_error(const runtime_error& le) _NOEXCEPT - : __imp_(le.__imp_) +runtime_error::runtime_error(const runtime_error& re) _NOEXCEPT + : __imp_(re.__imp_) { } runtime_error& -runtime_error::operator=(const runtime_error& le) _NOEXCEPT +runtime_error::operator=(const runtime_error& re) _NOEXCEPT { - __imp_ = le.__imp_; + __imp_ = re.__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 {}