Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #79567
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Why does this work in MSVC 2019... |
| Date | 2021-05-18 14:59 -0700 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <s81dc0$1b1r$1@gioia.aioe.org> (permalink) |
| References | <s7uss6$12f5$1@gioia.aioe.org> <ZMWdnfgfS_tueT79nZ2dnUU78RfNnZ2d@brightview.co.uk> |
On 5/18/2021 9:01 AM, Mike Terry wrote:
> On 18/05/2021 00:05, Chris M. Thomasson wrote:
>> I don't think this should work at all! It should segfault.
>> _______________________________
[...]
>> _______________________________
>
> Posting around 150 lines of code, then asking "why doesn't this
> segfault?" with no further explanation isn't good. It would have been
> helpful at least have said which bit of code you thought should produce
> a segfault...
Yeah, sorry about that.
> OK, so I guess your issue is with the two search_id functions, which
> return a reference to a local result, e.g.:
>
> > set_t::iterator const& search_id(unsigned long id) const
> > {
> > return m_set.find(id);
> > }
>
> When these are used you expect a segfault, but when I run the code (MSVS
> 17) there is no seg-fault because the original iterator storage on the
> stack hasn't been overwritten at that point. (There is a compile
> warning "returning address of local variable or temporary".)
>
> The obvious correct approach would be to just return the iterator by
> value. (And I'd wonder why would you want to make it const, but I
> suppose this is some kind of experiment rather than production code.)
It is a crude quick experiment. I never used is_transparent before. Then
I noticed that MSVC actually runs the bugged code. I got the warnings as
well, but still wondered about why it ran to completion.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-17 16:05 -0700
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-17 16:11 -0700
Re: Why does this work in MSVC 2019... Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-05-17 23:24 +0000
Re: Why does this work in MSVC 2019... "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2021-05-18 22:29 +0200
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-18 15:09 -0700
Re: Why does this work in MSVC 2019... Christian Gollwitzer <auriocus@gmx.de> - 2021-05-19 07:57 +0200
Re: Why does this work in MSVC 2019... James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-05-19 09:58 -0400
Re: Why does this work in MSVC 2019... Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2021-05-18 17:01 +0100
Re: Why does this work in MSVC 2019... Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-18 18:12 +0200
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-18 14:50 -0700
Re: Why does this work in MSVC 2019... Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-19 01:42 +0200
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-18 16:48 -0700
Re: Why does this work in MSVC 2019... Öö Tiib <ootiib@hot.ee> - 2021-05-18 17:55 -0700
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-18 20:06 -0700
Re: Why does this work in MSVC 2019... Paavo Helde <myfirstname@osa.pri.ee> - 2021-05-19 09:50 +0300
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-19 00:45 -0700
Re: Why does this work in MSVC 2019... Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-19 07:02 +0200
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-19 00:46 -0700
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-18 15:10 -0700
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-18 14:59 -0700
Re: Why does this work in MSVC 2019... Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-05-20 03:44 +0300
Re: Why does this work in MSVC 2019... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-05-19 20:38 -0700
csiph-web