Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #80138
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: A way around _HAS_ITERATOR_DEBUGGING |
| Date | 2021-06-03 20:18 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <s9b2se$jrs$1@dont-email.me> (permalink) |
| References | <s97uob$306$1@dont-email.me> <s98238$pm4$1@dont-email.me> <s9848m$9te$1@dont-email.me> <s9a6vj$r21$1@gioia.aioe.org> <s9ar5t$hik$1@dont-email.me> |
03.06.2021 18:06 James Kuyper kirjutas: > On 6/3/21 5:21 AM, Juha Nieminen wrote: >> Bonita Montero <Bonita.Montero@gmail.com> wrote: >>>>> Because i needed something like ptr = &*vec.end() and MSVC has iterator >>>>> -debugging by default >>> >>>> Dereferencing vec.end() is UB, ... >>> >>> In theory, but there's for sure no actual vector-implementation >>> where this doesn't work as long as you don't read from or write >>> to the reference. >> >> The problem with relying on undefined behavior is that you have no >> guarantees about what the compiler will do to your code. > > The C standard, while describing the unary & operator,says "If the > operand is the result of a unary * operator, neither that operator nor > the & operator is evaluated and the result is as if both were omitted, > except that the constraints on the operators still apply and the result > is not an lvalue." (C 6.5.3.2p3). > > I could find no corresponding statement in the C++ standard, but > shouldn't there be one? The C++ version would have to be more > complicated, to deal with issues that can't come up in C, such as > operator overloads. However, is there any good reason why there > shouldn't be a similar clause in the C++ standard? That would make > Bonita's code perfectly safe. C does not have user-defined operators. In C++ every iterator has its own implementation of operator*() and there is no guarantee that the operator & would exactly undo that operation. Indeed, typically it cannot and does not. Typically the result of &*iter is a pointer, not an iterator, and that's exactly why one might use such a construction in the first place. So in C++ one just cannot "cancel" &* as the result would be of a wrong type. It might be possible to make it happen (maybe by adding a special operator()&* to the standard which iterator classes would use for converting an iterator into a pointer), but the needed legalese seems daunting, and the benefits seem pretty meager (satisfying one angry Bonita Montero somewhere on the internet; everybody else is happy with vec.data()+vec.size()).
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-02 14:49 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-06-02 15:07 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-02 15:12 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-06-02 20:27 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING red floyd <myob@its.invalid> - 2021-06-02 14:24 -0700
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-03 00:54 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Öö Tiib <ootiib@hot.ee> - 2021-06-02 17:30 -0700
Re: A way around _HAS_ITERATOR_DEBUGGING Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-02 16:46 +0300
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-02 16:23 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-02 19:43 +0300
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-02 18:57 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-02 21:13 +0300
Re: A way around _HAS_ITERATOR_DEBUGGING James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-02 17:23 -0400
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-03 00:53 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-03 00:52 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-02 18:59 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Juha Nieminen <nospam@thanks.invalid> - 2021-06-03 09:21 +0000
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-03 11:33 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Bo Persson <bo@bo-persson.se> - 2021-06-03 12:17 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-03 12:25 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Juha Nieminen <nospam@thanks.invalid> - 2021-06-03 17:49 +0000
Re: A way around _HAS_ITERATOR_DEBUGGING MrSpook_ujp@3p26kggzpvpn2h.gov.uk - 2021-06-04 07:43 +0000
Re: A way around _HAS_ITERATOR_DEBUGGING James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-03 11:06 -0400
Re: A way around _HAS_ITERATOR_DEBUGGING David Brown <david.brown@hesbynett.no> - 2021-06-03 19:07 +0200
Re: A way around _HAS_ITERATOR_DEBUGGING Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-03 20:18 +0300
Re: A way around _HAS_ITERATOR_DEBUGGING Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-06-04 10:22 +0100
Re: A way around _HAS_ITERATOR_DEBUGGING Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-04 14:19 +0300
Re: A way around _HAS_ITERATOR_DEBUGGING Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-06-04 13:07 +0100
Re: A way around _HAS_ITERATOR_DEBUGGING James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-04 10:40 -0400
Re: A way around _HAS_ITERATOR_DEBUGGING Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-04 19:28 +0300
Re: A way around _HAS_ITERATOR_DEBUGGING James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-04 13:04 -0400
Re: A way around _HAS_ITERATOR_DEBUGGING "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-06-04 13:30 -0700
Re: A way around _HAS_ITERATOR_DEBUGGING MrSpook_6qpp@dggw8.org - 2021-06-05 09:28 +0000
Re: A way around _HAS_ITERATOR_DEBUGGING Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-04 23:45 +0300
Re: A way around _HAS_ITERATOR_DEBUGGING Juha Nieminen <nospam@thanks.invalid> - 2021-06-03 17:52 +0000
csiph-web