Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #68443
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Strange code-generation |
| Date | 2019-09-16 16:59 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <qlo4fl$hv4$1@dont-email.me> (permalink) |
| References | <qlo0kb$uhe$1@news.albasani.net> |
On 16.09.2019 15:53, Bonita Montero wrote:
> I just experimented a bit with downcasting to a derived class.
> So here's the code:
>
> struct A
> {
> int a, b, c;
> };
>
> struct B
> {
> int d, e, f;
> };
>
> struct D : public A, public B
> {
> int i, j, k;
> };
>
> D *f( B &b )
> {
> return &static_cast<D &>(b);
> }
>
> This is what you will expect ... with g++:
>
> leaq -12(%rdi), %rax
> ret
>
> This is what makes MSVC from the above code
>
> xor edx, edx
> lea rax, QWORD PTR [rcx-12]
> test rcx, rcx
> cmove rax, rdx
> ret 0
>
> So MSVC keeps a nullpointer when the input was also a nullpointer.
> Is there any requirement of the standard that mandates this behaviour?
> I think it would be even stupid to include that into the standard.
In standard C++ one cannot legally construct a "null reference", so the
standard cannot mandate any behavior regarding them. The special
handling of null only applies to the pointer form of static_cast<>.
However, an implementation may define behavior for things which are UB
by the standard. MSVC supports things like this==nullptr (see e.g.
CWnd::GetSafeHwnd() function), so maybe it supports "null references" as
well, possibly for backward compatibility with their own old code.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-16 14:53 +0200
Re: Strange code-generation Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-16 16:59 +0300
Re: Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-16 21:08 +0200
Re: Strange code-generation Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-18 08:47 -0700
Re: Strange code-generation Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-18 21:06 +0300
Re: Strange code-generation Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-09 05:52 -0800
Re: Strange code-generation "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-11-09 19:15 +0100
Re: Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-19 19:05 +0200
Re: Strange code-generation David Brown <david.brown@hesbynett.no> - 2019-09-19 19:34 +0200
Re: Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-19 20:05 +0200
Re: Strange code-generation Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-19 22:00 +0300
Re: Strange code-generation David Brown <david.brown@hesbynett.no> - 2019-09-20 08:21 +0200
csiph-web