1 // Copyright (C) 2018-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // rope (SGI extension)
23 #include <testsuite_hooks.h>
28 using __gnu_cxx::crope
;
31 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
32 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
33 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
34 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
35 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
37 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
38 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
39 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
40 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
41 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
43 // Create ropes with leaf nodes longer than __lazy_threshold = 128
44 // so substring nodes will be created by the next step
45 crope
leaf_rope_a(str_a
);
46 crope
leaf_rope_b(str_b
);
48 // Create ropes with substring nodes referencing the leaf nodes
50 crope
substring_rope_a(leaf_rope_a
.begin() + 1,
51 leaf_rope_a
.begin() + 199);
52 crope
substring_rope_b(leaf_rope_b
.begin() + 1,
53 leaf_rope_b
.begin() + 199);
55 // Create iterators to substring_rope_a
56 crope::const_iterator cit_orig
= substring_rope_a
.begin();
57 crope::iterator mit_orig
= substring_rope_a
.mutable_begin();
59 // Dereference the iterators so they cache a portion of the substring
60 // node in their internal buffers
64 // Copy the original iterators, via both copy constructors and
65 // assignment operators. Prior to the bug fix, these iterators
66 // retained pointers to the internal buffers of the original
68 crope::const_iterator
cit_copy(cit_orig
);
69 crope::iterator
mit_copy(mit_orig
);
70 crope::const_iterator cit_assign
; cit_assign
= cit_orig
;
71 crope::iterator mit_assign
; mit_assign
= mit_orig
;
73 // Modify the original iterators to refer to substring_rope_b
74 cit_orig
= substring_rope_b
.begin();
75 mit_orig
= substring_rope_b
.mutable_begin();
77 // Dereference the original iterators so they fill their internal
78 // buffers with part of substring_rope_b
82 // Verify that the copied iterators return data from
83 // substring_rope_a, not substring_rope_b
84 VERIFY(*cit_copy
== 'a');
85 VERIFY(*mit_copy
== 'a');
86 VERIFY(*cit_assign
== 'a');
87 VERIFY(*mit_assign
== 'a');