Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #79596

Re: Why does this work in MSVC 2019...

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-19 00:45 -0700
Organization Aioe.org NNTP Server
Message-ID <s82fm0$11c1$1@gioia.aioe.org> (permalink)
References (4 earlier) <s81jdl$272$1@dont-email.me> <s81jp6$1kfb$1@gioia.aioe.org> <f7503b30-9b74-4c22-a265-71db5e620f42n@googlegroups.com> <s81vc4$16fq$1@gioia.aioe.org> <s82ceq$u3c$1@dont-email.me>

Show all headers | View raw


On 5/18/2021 11:50 PM, Paavo Helde wrote:
> 19.05.2021 06:06 Chris M. Thomasson kirjutas:
>> On 5/18/2021 5:55 PM, Öö Tiib wrote:
>>> The segfault indicates that  gcc allows it to run as well unless you 
>>> mean
>>> that the compiler segfaults (that i've not seen gcc to do for ages).
>>
>> Yes, GCC allows it to run with warnings, and segfaults, and does not 
>> allow the bugged program to run to completion.
> 
> It's not GCC, but the hardware+OS which kills the running program. You 
> can compile the program with GCC for a platform without memory 
> protection (like 8086) and it will never segfault (because there are 
> neither segments nor faults). It might do other funny things though.
> 
>> MSVC allows that now. It compiles the bugged code, spits out a couple 
>> of warnings, and lets the compiled program run to completion. Strange.
> 
> This is normal for undefined behavior. Anything would be normal.
> 
> OTOH, it's not normal for a programmer to ignore compiler warnings about 
> returning references to temporaries. You might want to use the "Treat 
> Specific Errors as Warnings" compiler feature for this warning 
> (/we"4172" with MSVC).
> 
> The only reason this is a warning and not an error is because UB 
> formally only appears when dereferencing the invalid pointer/reference, 
> returning it from a function is actually fine.

100% agreed! I saw the warnings, but was interested into why the program 
was allowed to run to completion under MSVC. Then I tried it GCC, 
different things occurred. Its the nature of the beast wrt UB. I thank 
you and everybody else for their time and patience.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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