]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2018-2023 Free Software Foundation, Inc. |
3ffa55de JS |
2 | // |
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) | |
7 | // any later version. | |
8 | ||
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. | |
13 | ||
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/>. | |
17 | ||
18 | // rope (SGI extension) | |
19 | ||
20 | // { dg-do run } | |
21 | ||
22 | #include <ext/rope> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | void | |
26 | test01() | |
27 | { | |
28 | using __gnu_cxx::crope; | |
29 | ||
30 | char str_a[] = | |
31 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |
32 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |
33 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |
34 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |
35 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | |
36 | char str_b[] = | |
37 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" | |
38 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" | |
39 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" | |
40 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" | |
41 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; | |
42 | ||
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); | |
47 | ||
48 | // Create ropes with substring nodes referencing the leaf nodes | |
49 | // of the prior ropes | |
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); | |
54 | ||
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(); | |
58 | ||
59 | // Dereference the iterators so they cache a portion of the substring | |
60 | // node in their internal buffers | |
61 | *cit_orig; | |
62 | *mit_orig; | |
63 | ||
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 | |
67 | // iterators. | |
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; | |
72 | ||
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(); | |
76 | ||
77 | // Dereference the original iterators so they fill their internal | |
78 | // buffers with part of substring_rope_b | |
79 | *cit_orig; | |
80 | *mit_orig; | |
81 | ||
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'); | |
88 | } | |
89 | ||
90 | int | |
91 | main() | |
92 | { | |
93 | test01(); | |
94 | return 0; | |
95 | } |