C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Calling methods on a nullptr

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Mon, 28 Oct 2024 13:23:25 +0100
On 28/10/2024 12.45, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Mon, Oct 28, 2024 at 8:08 AM Jens Maurer wrote:
>>
>> And
>>
>> T *p = nullptr;
>> static_cast<T&>(*p).f();
>>
>> would also be ok, despite the fact that empty lvalues don't exist?
>
>
> Are you really saying that the following "Hello World" program is okay?

No, I'm saying that it was undefined behavior all along.

Jens


> #include <iostream>
>
> struct T {
> static void f(void) { std::cout << "Hello World\n"; }
> };
>
> int main(void)
> {
> T *p = nullptr;
> static_cast<T&>(*p).f();
> }

Received on 2024-10-28 12:23:29