Skip to content

Commit c04441e

Browse files
member call on object outside its lifetime is not allowed in a constant expression
1 parent a72b619 commit c04441e

File tree

14 files changed

+223
-133
lines changed

14 files changed

+223
-133
lines changed

libcxx/include/__tree

Lines changed: 71 additions & 68 deletions
Large diffs are not rendered by default.

libcxx/include/map

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -639,21 +639,21 @@ template <class _Key,
639639
bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
640640
class __map_value_compare : private _Compare {
641641
public:
642-
_LIBCPP_HIDE_FROM_ABI __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
642+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
643643
: _Compare() {}
644-
_LIBCPP_HIDE_FROM_ABI __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
644+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
645645
: _Compare(__c) {}
646-
_LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return *this; }
647-
_LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
646+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const _Compare& key_comp() const _NOEXCEPT { return *this; }
647+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _CP& __x, const _CP& __y) const {
648648
return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);
649649
}
650-
_LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
650+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _CP& __x, const _Key& __y) const {
651651
return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
652652
}
653-
_LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
653+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _Key& __x, const _CP& __y) const {
654654
return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
655655
}
656-
_LIBCPP_HIDE_FROM_ABI void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Compare>) {
656+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Compare>) {
657657
using std::swap;
658658
swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
659659
}
@@ -868,37 +868,37 @@ public:
868868
typedef value_type& reference;
869869
typedef typename _NodeTypes::__map_value_type_pointer pointer;
870870

871-
_LIBCPP_HIDE_FROM_ABI __map_iterator() _NOEXCEPT {}
871+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator() _NOEXCEPT {}
872872

873-
_LIBCPP_HIDE_FROM_ABI __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
873+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
874874

875-
_LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
876-
_LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
875+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __i_->__get_value(); }
876+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
877877

878-
_LIBCPP_HIDE_FROM_ABI __map_iterator& operator++() {
878+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator& operator++() {
879879
++__i_;
880880
return *this;
881881
}
882-
_LIBCPP_HIDE_FROM_ABI __map_iterator operator++(int) {
882+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator operator++(int) {
883883
__map_iterator __t(*this);
884884
++(*this);
885885
return __t;
886886
}
887887

888-
_LIBCPP_HIDE_FROM_ABI __map_iterator& operator--() {
888+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator& operator--() {
889889
--__i_;
890890
return *this;
891891
}
892-
_LIBCPP_HIDE_FROM_ABI __map_iterator operator--(int) {
892+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator operator--(int) {
893893
__map_iterator __t(*this);
894894
--(*this);
895895
return __t;
896896
}
897897

898-
friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_iterator& __x, const __map_iterator& __y) {
898+
friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const __map_iterator& __x, const __map_iterator& __y) {
899899
return __x.__i_ == __y.__i_;
900900
}
901-
friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {
901+
friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {
902902
return __x.__i_ != __y.__i_;
903903
}
904904

@@ -924,39 +924,39 @@ public:
924924
typedef const value_type& reference;
925925
typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
926926

927-
_LIBCPP_HIDE_FROM_ABI __map_const_iterator() _NOEXCEPT {}
927+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator() _NOEXCEPT {}
928928

929-
_LIBCPP_HIDE_FROM_ABI __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
929+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
930930
_LIBCPP_HIDE_FROM_ABI
931-
__map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {}
931+
_LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {}
932932

933-
_LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
934-
_LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
933+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __i_->__get_value(); }
934+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
935935

936-
_LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator++() {
936+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator& operator++() {
937937
++__i_;
938938
return *this;
939939
}
940-
_LIBCPP_HIDE_FROM_ABI __map_const_iterator operator++(int) {
940+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator operator++(int) {
941941
__map_const_iterator __t(*this);
942942
++(*this);
943943
return __t;
944944
}
945945

946-
_LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator--() {
946+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator& operator--() {
947947
--__i_;
948948
return *this;
949949
}
950-
_LIBCPP_HIDE_FROM_ABI __map_const_iterator operator--(int) {
950+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator operator--(int) {
951951
__map_const_iterator __t(*this);
952952
--(*this);
953953
return __t;
954954
}
955955

956-
friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) {
956+
friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) {
957957
return __x.__i_ == __y.__i_;
958958
}
959-
friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {
959+
friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {
960960
return __x.__i_ != __y.__i_;
961961
}
962962

libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
// class map
1212

13-
// bool empty() const;
13+
// bool empty() const;// constexpr since C++26
1414

1515
#include <map>
1616
#include <cassert>
1717

1818
#include "test_macros.h"
1919
#include "min_allocator.h"
2020

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
{
2323
typedef std::map<int, double> M;
2424
M m;
@@ -39,6 +39,13 @@ int main(int, char**) {
3939
assert(m.empty());
4040
}
4141
#endif
42+
return true;
43+
}
4244

45+
int main(int, char**) {
46+
assert(test());
47+
#if TEST_STD_VER >= 26
48+
static_assert(test());
49+
#endif
4350
return 0;
4451
}

libcxx/test/std/containers/associative/map/map.access/empty.verify.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@
1010

1111
// class map
1212

13-
// bool empty() const noexcept;
13+
// bool empty() const noexcept;// constexpr since C++26
1414

1515
// UNSUPPORTED: c++03, c++11, c++14, c++17
1616

1717
#include <map>
1818

19-
void f() {
19+
bool test() {
2020
std::map<int, int> c;
2121
c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
22+
return true;
23+
}
24+
25+
int main() {
26+
assert(test());
27+
#if TEST_STD_VER >= 26
28+
static_assert(test());
29+
#endif
2230
}

libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// class map
1212

13-
// mapped_type& operator[](const key_type& k);
13+
// mapped_type& operator[](const key_type& k);// constexpr since C++26
1414

1515
#include <map>
1616
#include <cassert>
@@ -23,7 +23,7 @@
2323
# include "container_test_types.h"
2424
#endif
2525

26-
int main(int, char**) {
26+
TEST_CONSTEXPR_CXX26 bool test() {
2727
{
2828
typedef std::pair<const int, double> V;
2929
V ar[] = {
@@ -135,6 +135,13 @@ int main(int, char**) {
135135
assert(m.size() == 8);
136136
}
137137
#endif
138+
return true;
139+
}
138140

141+
int main(int, char**) {
142+
assert(test());
143+
#if TEST_STD_VER >= 26
144+
static_assert(test());
145+
#endif
139146
return 0;
140147
}

libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// class map
1414

15-
// mapped_type& operator[](key_type&& k);
15+
// mapped_type& operator[](key_type&& k);// constexpr since C++26
1616

1717
#include <map>
1818
#include <cassert>
@@ -23,7 +23,7 @@
2323
#include "min_allocator.h"
2424
#include "container_test_types.h"
2525

26-
int main(int, char**) {
26+
TEST_CONSTEXPR_CXX26 bool test() {
2727
{
2828
std::map<MoveOnly, double> m;
2929
assert(m.size() == 0);
@@ -75,6 +75,13 @@ int main(int, char**) {
7575
}
7676
}
7777
}
78+
return true;
79+
}
7880

81+
int main(int, char**) {
82+
assert(test());
83+
#if TEST_STD_VER >= 26
84+
static_assert(test());
85+
#endif
7986
return 0;
8087
}

libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@
1212

1313
// class map
1414

15-
// mapped_type& operator[](const key_type& k);
15+
// mapped_type& operator[](const key_type& k);// constexpr since C++26
1616

1717
// https://llvm.org/PR16542
1818

1919
#include <map>
2020
#include <tuple>
2121

22-
int main(int, char**) {
22+
TEST_CONSTEXPR_CXX26 bool test() {
2323
std::map<std::tuple<int, int>, std::size_t> m;
2424
m[std::make_tuple(2, 3)] = 7;
25+
return true;
26+
}
2527

28+
int main(int, char**) {
29+
assert(test());
30+
#if TEST_STD_VER >= 26
31+
static_assert(test());
32+
#endif
2633
return 0;
2734
}

libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010

1111
// class map
1212

13-
// iterator begin();
14-
// const_iterator begin() const;
15-
// iterator end();
16-
// const_iterator end() const;
13+
// iterator begin();// constexpr since C++26
14+
// const_iterator begin() const;// constexpr since C++26
15+
// iterator end();// constexpr since C++26
16+
// const_iterator end() const;// constexpr since C++26
1717
//
18-
// reverse_iterator rbegin();
19-
// const_reverse_iterator rbegin() const;
20-
// reverse_iterator rend();
21-
// const_reverse_iterator rend() const;
18+
// reverse_iterator rbegin();// constexpr since C++26
19+
// const_reverse_iterator rbegin() const;// constexpr since C++26
20+
// reverse_iterator rend();// constexpr since C++26
21+
// const_reverse_iterator rend() const;// constexpr since C++26
2222
//
23-
// const_iterator cbegin() const;
24-
// const_iterator cend() const;
25-
// const_reverse_iterator crbegin() const;
26-
// const_reverse_iterator crend() const;
23+
// const_iterator cbegin() const;// constexpr since C++26
24+
// const_iterator cend() const;// constexpr since C++26
25+
// const_reverse_iterator crbegin() const;// constexpr since C++26
26+
// const_reverse_iterator crend() const;// constexpr since C++26
2727

2828
#include <map>
2929
#include <cassert>
@@ -32,7 +32,7 @@
3232
#include "test_macros.h"
3333
#include "min_allocator.h"
3434

35-
int main(int, char**) {
35+
TEST_CONSTEXPR_CXX26 bool test() {
3636
{
3737
typedef std::pair<const int, double> V;
3838
V ar[] = {V(1, 1), V(1, 1.5), V(1, 2), V(2, 1), V(2, 1.5), V(2, 2), V(3, 1), V(3, 1.5),
@@ -156,6 +156,13 @@ int main(int, char**) {
156156
assert(!(cii != ii1));
157157
}
158158
#endif
159+
return true;
160+
}
159161

162+
int main(int, char**) {
163+
assert(test());
164+
#if TEST_STD_VER >= 26
165+
static_assert(test());
166+
#endif
160167
return 0;
161168
}

libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// class map
1212

13-
// size_type max_size() const;
13+
// size_type max_size() const;// constexpr since C++26
1414

1515
#include <cassert>
1616
#include <limits>
@@ -20,7 +20,7 @@
2020
#include "test_allocator.h"
2121
#include "test_macros.h"
2222

23-
int main(int, char**) {
23+
TEST_CONSTEXPR_CXX26 bool test() {
2424
typedef std::pair<const int, int> KV;
2525
{
2626
typedef limited_allocator<KV, 10> A;
@@ -44,6 +44,13 @@ int main(int, char**) {
4444
assert(c.max_size() <= max_dist);
4545
assert(c.max_size() <= alloc_max_size(c.get_allocator()));
4646
}
47+
return true;
48+
}
4749

50+
int main(int, char**) {
51+
assert(test());
52+
#if TEST_STD_VER >= 26
53+
static_assert(test());
54+
#endif
4855
return 0;
4956
}

libcxx/test/std/containers/associative/map/map.access/size.pass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
// class map
1212

13-
// size_type size() const;
13+
// size_type size() const;// constexpr since C++26
1414

1515
#include <map>
1616
#include <cassert>
1717

1818
#include "test_macros.h"
1919
#include "min_allocator.h"
2020

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
{
2323
typedef std::map<int, double> M;
2424
M m;
@@ -55,6 +55,13 @@ int main(int, char**) {
5555
assert(m.size() == 0);
5656
}
5757
#endif
58+
return true;
59+
}
5860

61+
int main(int, char**) {
62+
assert(test());
63+
#if TEST_STD_VER >= 26
64+
static_assert(test());
65+
#endif
5966
return 0;
6067
}

0 commit comments

Comments
 (0)