Index: include/string =================================================================== --- include/string +++ include/string @@ -627,13 +627,13 @@ #else template ::value> struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( - noexcept(++(declval<_Iter&>())) && - is_nothrow_assignable<_Iter&, _Iter>::value && - noexcept(declval<_Iter>() == declval<_Iter>()) && + noexcept(++(declval<_Iter&>())) && + is_nothrow_assignable<_Iter&, _Iter>::value && + noexcept(declval<_Iter>() == declval<_Iter>()) && noexcept(*declval<_Iter>()) )) {}; -template +template struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {}; #endif @@ -1420,7 +1420,7 @@ _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT; - + _LIBCPP_INLINE_VISIBILITY bool __is_long() const _NOEXCEPT {return bool(__r_.first().__s.__size_ & __short_mask);} @@ -1682,7 +1682,7 @@ -> basic_string<_CharT, _Traits, _Allocator>; #endif - + template inline void @@ -2525,7 +2525,7 @@ const basic_string __temp (__first, __last, __alloc()); append(__temp.data(), __temp.size()); } - else + else { if (__cap - __sz < __n) __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); @@ -3824,7 +3824,7 @@ template inline -void +void basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT { clear(); @@ -3834,7 +3834,7 @@ __set_long_cap(0); __set_short_size(0); } -} +} // operator== @@ -4227,18 +4227,21 @@ const typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::npos; -template -struct _LIBCPP_TEMPLATE_VIS hash > - : public unary_function, size_t> +template +struct _LIBCPP_TEMPLATE_VIS + hash, _Allocator> > + : public unary_function< + basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t> { size_t - operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT; + operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT; }; -template + +template size_t -hash >::operator()( - const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT +hash, _Allocator> >::operator()( + const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT { return __do_string_hash(__val.data(), __val.data() + __val.size()); } @@ -4331,7 +4334,7 @@ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) -#if _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals { Index: test/std/strings/basic.string.hash/char_type_hash.fail.cpp =================================================================== --- /dev/null +++ test/std/strings/basic.string.hash/char_type_hash.fail.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// + +// Test that hash specializations for require "char_traits<_CharT>" not just any "_Trait". + +#include + +template +struct trait // copied from <__string> +{ + typedef _CharT char_type; + typedef int int_type; + typedef std::streamoff off_type; + typedef std::streampos pos_type; + typedef std::mbstate_t state_type; + + static inline void assign(char_type& __c1, const char_type& __c2) { + __c1 = __c2; + } + static inline bool eq(char_type __c1, char_type __c2) { return __c1 == __c2; } + static inline bool lt(char_type __c1, char_type __c2) { return __c1 < __c2; } + + static int compare(const char_type* __s1, const char_type* __s2, size_t __n); + static size_t length(const char_type* __s); + static const char_type* find(const char_type* __s, size_t __n, + const char_type& __a); + + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); + static char_type* assign(char_type* __s, size_t __n, char_type __a); + + static inline int_type not_eof(int_type __c) { + return eq_int_type(__c, eof()) ? ~eof() : __c; + } + static inline char_type to_char_type(int_type __c) { return char_type(__c); } + static inline int_type to_int_type(char_type __c) { return int_type(__c); } + static inline bool eq_int_type(int_type __c1, int_type __c2) { + return __c1 == __c2; + } + static inline int_type eof() { return int_type(EOF); } +}; + +template +void test() { + typedef std::basic_string > str_t; + std::hash + h; // call to implicitly-deleted default constructor of 'std::hash' {{*}}}} +} + +int main(int, char**) { + test(); + test(); + test(); + test(); + + return 0; +}