diff options
author | Richard Smith <richard@metafoo.co.uk> | 2020-11-11 17:12:18 -0800 |
---|---|---|
committer | Richard Smith <richard@metafoo.co.uk> | 2020-12-07 12:53:07 -0800 |
commit | 98f76adf4e941738c0b9fe3b9965fa63603e9c89 (patch) | |
tree | d64cbb9732c788a5506b4b7a6483eedba6864907 /libcxx | |
parent | 2ac4d0f45a2a301163ca53f3e23e675f4f5bdbd3 (diff) | |
download | llvm-project-98f76adf4e941738c0b9fe3b9965fa63603e9c89.tar.gz |
Add new 'preferred_name' attribute.
This attribute permits a typedef to be associated with a class template
specialization as a preferred way of naming that class template
specialization. This permits us to specify that (for example) the
preferred way to express 'std::basic_string<char>' is as 'std::string'.
The attribute is applied to the various class templates in libc++ that have
corresponding well-known typedef names.
Differential Revision: https://reviews.llvm.org/D91311
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/__config | 6 | ||||
-rw-r--r-- | libcxx/include/iosfwd | 32 | ||||
-rw-r--r-- | libcxx/include/regex | 93 | ||||
-rw-r--r-- | libcxx/include/string | 29 | ||||
-rw-r--r-- | libcxx/include/string_view | 29 |
5 files changed, 142 insertions, 47 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config index d2fdf6785c7e..033cd8aea068 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1318,6 +1318,12 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #endif #endif // !defined(_LIBCPP_NODEBUG_TYPE) +#if __has_attribute(__preferred_name__) +#define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) +#else +#define _LIBCPP_PREFERRED_NAME(x) +#endif + #if defined(_LIBCPP_ABI_MICROSOFT) && \ (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) diff --git a/libcxx/include/iosfwd b/libcxx/include/iosfwd index 070fbe8bfad8..0a0de99ff3a7 100644 --- a/libcxx/include/iosfwd +++ b/libcxx/include/iosfwd @@ -185,6 +185,36 @@ typedef basic_ifstream<wchar_t> wifstream; typedef basic_ofstream<wchar_t> wofstream; typedef basic_fstream<wchar_t> wfstream; +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_PREFERRED_NAME(wios) basic_ios; + +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(streambuf) _LIBCPP_PREFERRED_NAME(wstreambuf) basic_streambuf; +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(istream) _LIBCPP_PREFERRED_NAME(wistream) basic_istream; +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(ostream) _LIBCPP_PREFERRED_NAME(wostream) basic_ostream; +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(iostream) _LIBCPP_PREFERRED_NAME(wiostream) basic_iostream; + +template <class _CharT, class _Traits, class _Allocator> + class _LIBCPP_PREFERRED_NAME(stringbuf) _LIBCPP_PREFERRED_NAME(wstringbuf) basic_stringbuf; +template <class _CharT, class _Traits, class _Allocator> + class _LIBCPP_PREFERRED_NAME(istringstream) _LIBCPP_PREFERRED_NAME(wistringstream) basic_istringstream; +template <class _CharT, class _Traits, class _Allocator> + class _LIBCPP_PREFERRED_NAME(ostringstream) _LIBCPP_PREFERRED_NAME(wostringstream) basic_ostringstream; +template <class _CharT, class _Traits, class _Allocator> + class _LIBCPP_PREFERRED_NAME(stringstream) _LIBCPP_PREFERRED_NAME(wstringstream) basic_stringstream; + +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(filebuf) _LIBCPP_PREFERRED_NAME(wfilebuf) basic_filebuf; +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(ifstream) _LIBCPP_PREFERRED_NAME(wifstream) basic_ifstream; +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(ofstream) _LIBCPP_PREFERRED_NAME(wofstream) basic_ofstream; +template <class _CharT, class _Traits> + class _LIBCPP_PREFERRED_NAME(fstream) _LIBCPP_PREFERRED_NAME(wfstream) basic_fstream; + template <class _State> class _LIBCPP_TEMPLATE_VIS fpos; typedef fpos<mbstate_t> streampos; typedef fpos<mbstate_t> wstreampos; @@ -210,6 +240,8 @@ template <class _CharT, // for <stdexcept> typedef basic_string<char, char_traits<char>, allocator<char> > string; typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring; +template <class _CharT, class _Traits, class _Allocator> + class _LIBCPP_PREFERRED_NAME(string) _LIBCPP_PREFERRED_NAME(wstring) basic_string; // Include other forward declarations here template <class _Tp, class _Alloc = allocator<_Tp> > diff --git a/libcxx/include/regex b/libcxx/include/regex index 7c5b2fd61b93..8578039bf6a2 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -2534,7 +2534,17 @@ __exit: template <class _CharT, class _Traits> class __lookahead; template <class _CharT, class _Traits = regex_traits<_CharT> > -class _LIBCPP_TEMPLATE_VIS basic_regex + class _LIBCPP_TEMPLATE_VIS basic_regex; + +typedef basic_regex<char> regex; +typedef basic_regex<wchar_t> wregex; + +template <class _CharT, class _Traits> +class + _LIBCPP_TEMPLATE_VIS + _LIBCPP_PREFERRED_NAME(regex) + _LIBCPP_PREFERRED_NAME(wregex) + basic_regex { public: // types: @@ -4879,13 +4889,21 @@ basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); } -typedef basic_regex<char> regex; -typedef basic_regex<wchar_t> wregex; - // sub_match +typedef sub_match<const char*> csub_match; +typedef sub_match<const wchar_t*> wcsub_match; +typedef sub_match<string::const_iterator> ssub_match; +typedef sub_match<wstring::const_iterator> wssub_match; + template <class _BidirectionalIterator> -class _LIBCPP_TEMPLATE_VIS sub_match +class + _LIBCPP_TEMPLATE_VIS + _LIBCPP_PREFERRED_NAME(csub_match) + _LIBCPP_PREFERRED_NAME(wcsub_match) + _LIBCPP_PREFERRED_NAME(ssub_match) + _LIBCPP_PREFERRED_NAME(wssub_match) + sub_match : public pair<_BidirectionalIterator, _BidirectionalIterator> { public: @@ -4920,11 +4938,6 @@ public: {return str().compare(__s);} }; -typedef sub_match<const char*> csub_match; -typedef sub_match<const wchar_t*> wcsub_match; -typedef sub_match<string::const_iterator> ssub_match; -typedef sub_match<wstring::const_iterator> wssub_match; - template <class _BiIter> inline _LIBCPP_INLINE_VISIBILITY bool @@ -5307,8 +5320,19 @@ operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) return __os << __m.str(); } +typedef match_results<const char*> cmatch; +typedef match_results<const wchar_t*> wcmatch; +typedef match_results<string::const_iterator> smatch; +typedef match_results<wstring::const_iterator> wsmatch; + template <class _BidirectionalIterator, class _Allocator> -class _LIBCPP_TEMPLATE_VIS match_results +class + _LIBCPP_TEMPLATE_VIS + _LIBCPP_PREFERRED_NAME(cmatch) + _LIBCPP_PREFERRED_NAME(wcmatch) + _LIBCPP_PREFERRED_NAME(smatch) + _LIBCPP_PREFERRED_NAME(wsmatch) + match_results { public: typedef _Allocator allocator_type; @@ -5628,11 +5652,6 @@ match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) swap(__ready_, __m.__ready_); } -typedef match_results<const char*> cmatch; -typedef match_results<const wchar_t*> wcmatch; -typedef match_results<string::const_iterator> smatch; -typedef match_results<wstring::const_iterator> wsmatch; - template <class _BidirectionalIterator, class _Allocator> bool operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, @@ -6216,7 +6235,21 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s, template <class _BidirectionalIterator, class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, class _Traits = regex_traits<_CharT> > -class _LIBCPP_TEMPLATE_VIS regex_iterator + class _LIBCPP_TEMPLATE_VIS regex_iterator; + +typedef regex_iterator<const char*> cregex_iterator; +typedef regex_iterator<const wchar_t*> wcregex_iterator; +typedef regex_iterator<string::const_iterator> sregex_iterator; +typedef regex_iterator<wstring::const_iterator> wsregex_iterator; + +template <class _BidirectionalIterator, class _CharT, class _Traits> +class + _LIBCPP_TEMPLATE_VIS + _LIBCPP_PREFERRED_NAME(cregex_iterator) + _LIBCPP_PREFERRED_NAME(wcregex_iterator) + _LIBCPP_PREFERRED_NAME(sregex_iterator) + _LIBCPP_PREFERRED_NAME(wsregex_iterator) + regex_iterator { public: typedef basic_regex<_CharT, _Traits> regex_type; @@ -6325,17 +6358,26 @@ regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() return *this; } -typedef regex_iterator<const char*> cregex_iterator; -typedef regex_iterator<const wchar_t*> wcregex_iterator; -typedef regex_iterator<string::const_iterator> sregex_iterator; -typedef regex_iterator<wstring::const_iterator> wsregex_iterator; - // regex_token_iterator template <class _BidirectionalIterator, class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, class _Traits = regex_traits<_CharT> > -class _LIBCPP_TEMPLATE_VIS regex_token_iterator + class _LIBCPP_TEMPLATE_VIS regex_token_iterator; + +typedef regex_token_iterator<const char*> cregex_token_iterator; +typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; +typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; +typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; + +template <class _BidirectionalIterator, class _CharT, class _Traits> +class + _LIBCPP_TEMPLATE_VIS + _LIBCPP_PREFERRED_NAME(cregex_token_iterator) + _LIBCPP_PREFERRED_NAME(wcregex_token_iterator) + _LIBCPP_PREFERRED_NAME(sregex_token_iterator) + _LIBCPP_PREFERRED_NAME(wsregex_token_iterator) + regex_token_iterator { public: typedef basic_regex<_CharT, _Traits> regex_type; @@ -6613,11 +6655,6 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() return *this; } -typedef regex_token_iterator<const char*> cregex_token_iterator; -typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; -typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; -typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; - // regex_replace template <class _OutputIterator, class _BidirectionalIterator, diff --git a/libcxx/include/string b/libcxx/include/string index 1f3f444727fd..b54fe2a93abd 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -666,8 +666,26 @@ struct __padding<_CharT, 1> #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT +#ifndef _LIBCPP_NO_HAS_CHAR8_T +typedef basic_string<char8_t> u8string; +#endif + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef basic_string<char16_t> u16string; +typedef basic_string<char32_t> u32string; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + template<class _CharT, class _Traits, class _Allocator> -class _LIBCPP_TEMPLATE_VIS basic_string +class + _LIBCPP_TEMPLATE_VIS +#ifndef _LIBCPP_NO_HAS_CHAR8_T + _LIBCPP_PREFERRED_NAME(u8string) +#endif +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + _LIBCPP_PREFERRED_NAME(u16string) + _LIBCPP_PREFERRED_NAME(u32string) +#endif + basic_string : private __basic_string_common<true> { public: @@ -4327,15 +4345,6 @@ swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, __lhs.swap(__rhs); } -#ifndef _LIBCPP_NO_HAS_CHAR8_T -typedef basic_string<char8_t> u8string; -#endif - -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS -typedef basic_string<char16_t> u16string; -typedef basic_string<char32_t> u32string; -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); diff --git a/libcxx/include/string_view b/libcxx/include/string_view index 7c3214fb2c2e..44ffb02c432d 100644 --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -192,7 +192,26 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template<class _CharT, class _Traits = char_traits<_CharT> > -class _LIBCPP_TEMPLATE_VIS basic_string_view { + class _LIBCPP_TEMPLATE_VIS basic_string_view; + +typedef basic_string_view<char> string_view; +#ifndef _LIBCPP_NO_HAS_CHAR8_T +typedef basic_string_view<char8_t> u8string_view; +#endif +typedef basic_string_view<char16_t> u16string_view; +typedef basic_string_view<char32_t> u32string_view; +typedef basic_string_view<wchar_t> wstring_view; + +template<class _CharT, class _Traits> +class + _LIBCPP_PREFERRED_NAME(string_view) +#ifndef _LIBCPP_NO_HAS_CHAR8_T + _LIBCPP_PREFERRED_NAME(u8string_view) +#endif + _LIBCPP_PREFERRED_NAME(u16string_view) + _LIBCPP_PREFERRED_NAME(u32string_view) + _LIBCPP_PREFERRED_NAME(wstring_view) + basic_string_view { public: // types typedef _Traits traits_type; @@ -776,14 +795,6 @@ basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __str); -typedef basic_string_view<char> string_view; -#ifndef _LIBCPP_NO_HAS_CHAR8_T -typedef basic_string_view<char8_t> u8string_view; -#endif -typedef basic_string_view<char16_t> u16string_view; -typedef basic_string_view<char32_t> u32string_view; -typedef basic_string_view<wchar_t> wstring_view; - // [string.view.hash] template<class _CharT> struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > > |