Skip to content

Commit 40673a0

Browse files
committed
[libc++] Always initialize __tree::{,const_}iterator
1 parent ec752c6 commit 40673a0

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

libcxx/include/__tree

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,7 @@ public:
646646
using reference = value_type&;
647647
using pointer = __rebind_pointer_t<_NodePtr, value_type>;
648648

649-
_LIBCPP_HIDE_FROM_ABI __tree_iterator() _NOEXCEPT
650-
#if _LIBCPP_STD_VER >= 14
651-
: __ptr_(nullptr)
652-
#endif
653-
{
654-
}
649+
_LIBCPP_HIDE_FROM_ABI __tree_iterator() _NOEXCEPT : __ptr_(nullptr) {}
655650

656651
_LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_np()->__value_; }
657652
_LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__get_np()->__value_); }
@@ -720,12 +715,7 @@ public:
720715
using reference = const value_type&;
721716
using pointer = __rebind_pointer_t<_NodePtr, const value_type>;
722717

723-
_LIBCPP_HIDE_FROM_ABI __tree_const_iterator() _NOEXCEPT
724-
#if _LIBCPP_STD_VER >= 14
725-
: __ptr_(nullptr)
726-
#endif
727-
{
728-
}
718+
_LIBCPP_HIDE_FROM_ABI __tree_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
729719

730720
private:
731721
typedef __tree_iterator<_Tp, __node_pointer, difference_type> __non_const_iterator;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// Check that map::iterator is initialized when default constructed
12+
13+
#include <cassert>
14+
#include <map>
15+
16+
template <class Iter>
17+
void test() {
18+
Iter iter;
19+
Iter iter2 = Iter();
20+
assert(iter == iter2);
21+
}
22+
23+
int main() {
24+
test<std::map<int, int>::iterator>();
25+
test<std::map<int, int>::const_iterator>();
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// Check that set::iterator is initialized when default constructed
12+
13+
#include <cassert>
14+
#include <set>
15+
16+
template <class Iter>
17+
void test() {
18+
Iter iter;
19+
Iter iter2 = Iter();
20+
assert(iter == iter2);
21+
}
22+
23+
int main() {
24+
test<std::set<int>::iterator>();
25+
test<std::set<int>::const_iterator>();
26+
}

0 commit comments

Comments
 (0)