Skip to content

Commit 1c7fe12

Browse files
committed
Fixes for LWG 2598, 2686, 2739, 2742, 2747, and 2759, which were adopted last week in Issaquah
llvm-svn: 286858
1 parent ccf2fa1 commit 1c7fe12

File tree

25 files changed

+504
-16
lines changed

25 files changed

+504
-16
lines changed

libcxx/include/algorithm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f)
877877
{
878878
for (; __first != __last; ++__first)
879879
__f(*__first);
880-
return _LIBCPP_EXPLICIT_MOVE(__f); // explicitly moved for (emulated) C++03
880+
return __f;
881881
}
882882

883883
// find

libcxx/include/chrono

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,8 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
10261026
time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
10271027
operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
10281028
{
1029-
return __lhs + (-__rhs);
1029+
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
1030+
return _Ret(__lhs.time_since_epoch() -__rhs);
10301031
}
10311032

10321033
// duration operator-(time_point x, time_point y);

libcxx/include/memory

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept
164164
template <class T> void return_temporary_buffer(T* p) noexcept;
165165
166166
template <class T> T* addressof(T& r) noexcept;
167+
template <class T> T* addressof(const T&& r) noexcept = delete;
167168
168169
template <class InputIterator, class ForwardIterator>
169170
ForwardIterator
@@ -675,7 +676,7 @@ _ValueType __libcpp_acquire_load(_ValueType const* __value) {
675676
#endif
676677
}
677678

678-
// addressof moved to <__functional_base>
679+
// addressof moved to <type_traits>
679680

680681
template <class _Tp> class allocator;
681682

libcxx/include/numeric

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ common_type_t<_Tp,_Up>
230230
gcd(_Tp __m, _Up __n)
231231
{
232232
static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types");
233+
static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" );
234+
static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
233235
using _Rp = common_type_t<_Tp,_Up>;
234236
using _Wp = make_unsigned_t<_Rp>;
235237
return static_cast<_Rp>(__gcd(static_cast<_Wp>(__abs<_Tp>()(__m)),
@@ -242,6 +244,8 @@ common_type_t<_Tp,_Up>
242244
lcm(_Tp __m, _Up __n)
243245
{
244246
static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types");
247+
static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" );
248+
static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" );
245249
if (__m == 0 || __n == 0)
246250
return 0;
247251

libcxx/include/string

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public:
102102
const allocator_type& a = allocator_type());
103103
basic_string(const basic_string& str, size_type pos, size_type n,
104104
const Allocator& a = Allocator());
105+
template<class T>
106+
basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
105107
explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
106108
basic_string(const value_type* s, const allocator_type& a = allocator_type());
107109
basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
@@ -789,6 +791,10 @@ public:
789791
_LIBCPP_INLINE_VISIBILITY
790792
basic_string(const basic_string& __str, size_type __pos,
791793
const allocator_type& __a = allocator_type());
794+
template<class _Tp>
795+
basic_string(const _Tp& __t, size_type __pos, size_type __n,
796+
const allocator_type& __a = allocator_type(),
797+
typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
792798
_LIBCPP_INLINE_VISIBILITY explicit
793799
basic_string(__self_view __sv);
794800
_LIBCPP_INLINE_VISIBILITY
@@ -1716,6 +1722,20 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
17161722
#endif
17171723
}
17181724

1725+
template <class _CharT, class _Traits, class _Allocator>
1726+
template <class _Tp>
1727+
basic_string<_CharT, _Traits, _Allocator>::basic_string(
1728+
const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
1729+
typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
1730+
: __r_(__a)
1731+
{
1732+
__self_view __sv = __self_view(__t).substr(__pos, __n);
1733+
__init(__sv.data(), __sv.size());
1734+
#if _LIBCPP_DEBUG_LEVEL >= 2
1735+
__get_db()->__insert_c(this);
1736+
#endif
1737+
}
1738+
17191739
template <class _CharT, class _Traits, class _Allocator>
17201740
inline _LIBCPP_INLINE_VISIBILITY
17211741
basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)

libcxx/include/string_view

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ namespace std {
164164
#include <__config>
165165

166166
#include <__string>
167-
#include <algorithm>
168167
#include <iterator>
169168
#include <__debug>
170169

@@ -320,8 +319,8 @@ public:
320319
{
321320
if (__pos > size())
322321
__throw_out_of_range("string_view::copy");
323-
size_type __rlen = _VSTD::min( __n, size() - __pos );
324-
copy_n(begin() + __pos, __rlen, __s );
322+
size_type __rlen = _VSTD::min(__n, size() - __pos);
323+
_Traits::copy(__s, data() + __pos, __rlen);
325324
return __rlen;
326325
}
327326

libcxx/include/system_error

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
219219
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
220220
221221
template <> struct hash<std::error_code>;
222+
template <> struct hash<std::error_condition>;
222223
223224
} // std
224225
@@ -629,6 +630,17 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<error_code>
629630
}
630631
};
631632

633+
template <>
634+
struct _LIBCPP_TYPE_VIS_ONLY hash<error_condition>
635+
: public unary_function<error_condition, size_t>
636+
{
637+
_LIBCPP_INLINE_VISIBILITY
638+
size_t operator()(const error_condition& __ec) const _NOEXCEPT
639+
{
640+
return static_cast<size_t>(__ec.value());
641+
}
642+
};
643+
632644
// system_error
633645

634646
class _LIBCPP_TYPE_VIS system_error

libcxx/include/type_traits

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
488488
}
489489
#endif
490490

491+
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_DELETED_FUNCTIONS)
492+
template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;
493+
#endif
494+
491495
struct __two {char __lx[2];};
492496

493497
// helper class:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// <functional>
11+
12+
// template <class T>
13+
// struct hash
14+
// : public unary_function<T, size_t>
15+
// {
16+
// size_t operator()(T val) const;
17+
// };
18+
19+
#include <system_error>
20+
#include <cassert>
21+
#include <type_traits>
22+
23+
#include "test_macros.h"
24+
25+
void
26+
test(int i)
27+
{
28+
typedef std::error_condition T;
29+
typedef std::hash<T> H;
30+
static_assert((std::is_same<H::argument_type, T>::value), "" );
31+
static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
32+
H h;
33+
T ec(i, std::system_category());
34+
const std::size_t result = h(ec);
35+
LIBCPP_ASSERT(result == i);
36+
((void)result); // Prevent unused warning
37+
}
38+
39+
int main()
40+
{
41+
test(0);
42+
test(2);
43+
test(10);
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
// <numeric>
12+
13+
// template<class _M, class _N>
14+
// constexpr common_type_t<_M,_N> gcd(_M __m, _N __n)
15+
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
18+
19+
#include <numeric>
20+
21+
22+
int main()
23+
{
24+
std::gcd(false, 4);
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
// <numeric>
12+
13+
// template<class _M, class _N>
14+
// constexpr common_type_t<_M,_N> gcd(_M __m, _N __n)
15+
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
18+
19+
#include <numeric>
20+
21+
22+
int main()
23+
{
24+
std::gcd(2, true);
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
// <numeric>
12+
13+
// template<class _M, class _N>
14+
// constexpr common_type_t<_M,_N> gcd(_M __m, _N __n)
15+
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
18+
19+
#include <numeric>
20+
21+
22+
int main()
23+
{
24+
std::gcd<volatile bool, int>(false, 4);
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
// <numeric>
12+
13+
// template<class _M, class _N>
14+
// constexpr common_type_t<_M,_N> gcd(_M __m, _N __n)
15+
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
18+
19+
#include <numeric>
20+
21+
22+
int main()
23+
{
24+
std::gcd<int, const bool>(2, true);
25+
}

libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.not_integral1.fail.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
// template<class _M, class _N>
1414
// constexpr common_type_t<_M,_N> gcd(_M __m, _N __n)
1515

16-
// Remarks: If either M or N is not an integer type, the program is ill-formed.
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
1718

1819
#include <numeric>
1920

libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.not_integral2.fail.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
// template<class _M, class _N>
1414
// constexpr common_type_t<_M,_N> gcd(_M __m, _N __n)
1515

16-
// Remarks: If either M or N is not an integer type, the program is ill-formed.
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
1718

1819
#include <numeric>
1920

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
// <numeric>
12+
13+
// template<class _M, class _N>
14+
// constexpr common_type_t<_M,_N> lcm(_M __m, _N __n)
15+
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
18+
19+
#include <numeric>
20+
21+
22+
int main()
23+
{
24+
std::lcm(false, 4);
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
// <numeric>
12+
13+
// template<class _M, class _N>
14+
// constexpr common_type_t<_M,_N> lcm(_M __m, _N __n)
15+
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
18+
19+
#include <numeric>
20+
21+
22+
int main()
23+
{
24+
std::lcm(2, true);
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
// <numeric>
12+
13+
// template<class _M, class _N>
14+
// constexpr common_type_t<_M,_N> lcm(_M __m, _N __n)
15+
16+
// Remarks: If either M or N is not an integer type,
17+
// or if either is (a possibly cv-qualified) bool, the program is ill-formed.
18+
19+
#include <numeric>
20+
21+
22+
int main()
23+
{
24+
std::lcm<volatile bool, int>(false, 4);
25+
}

0 commit comments

Comments
 (0)