1 // PR optimization/6713
2 // This testcase segfaulted on x86 because a dangling REG_EQUAL note
3 // resulted in incorrect substitutions later.
5 // { dg-options "-O2" }
7 template<typename _CharT> class basic_iterator
10 basic_iterator(_CharT* _p) : _M_current(_p) {}
11 basic_iterator& operator++() { ++_M_current; return *this; }
12 _CharT& operator*() const { return *_M_current; }
13 bool operator!=(basic_iterator &_rhs) { return _M_current != _rhs._M_current; }
19 template<typename _CharT> class basic_string
22 typedef unsigned int size_type;
23 typedef basic_iterator<_CharT> iterator;
29 size_type _M_capacity;
32 bool _M_is_leaked() const { return _M_references < 0; }
33 bool _M_is_shared() const { return _M_references > 0; }
34 void _M_set_leaked() { _M_references = -1; }
35 void _M_set_sharable() { _M_references = 0; }
46 mutable _Alloc_hider _M_dataplus;
48 _CharT* _M_data() const { return _M_dataplus._M_p; }
50 void _M_leak() { if (!_M_rep._M_is_leaked()) _M_leak_hard(); }
54 static void _M_leak_hard();
57 explicit basic_string(const _CharT* __s);
59 iterator begin() { _M_leak(); return iterator(_M_data()); }
61 iterator end() { _M_leak(); return iterator(_M_data() + this->size()); }
63 size_type size() const { return _M_rep._M_length; }
66 template<typename _CharT> basic_string<_CharT>::
67 basic_string(const _CharT* __s)
71 for (i=0; i<15; i++) {
75 _M_dataplus._raw[i] = __s[i];
78 _M_dataplus._raw[i] = 0;
79 _M_dataplus._M_p = _M_dataplus._raw;
82 _M_rep._M_capacity = i;
83 _M_rep._M_references = 1;
86 template<typename _CharT> int basic_string<_CharT>::count = 0;
88 template<typename _CharT> void basic_string<_CharT>::
94 typedef basic_string<char> string;
96 template int basic_string<char>::count;
103 void foo(string& str)
105 string::iterator it = str.begin();
106 string::iterator stop = str.end();
108 for (; it != stop; ++it)