C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A Small Question

From: Andre Kostur <andre_at_[hidden]>
Date: Sat, 4 Jan 2025 13:29:14 -0800
Afraid you’re in the wrong place. This mailing list is about proposals to
change the language, not as a helpdesk. Reddit might be a better place to
ask.

On Sat, Jan 4, 2025 at 1:26 PM 李 秋逸 via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello everyone. I hava a small and maybe useless question about the
> cplusplus standard. Maybe there are some experts can help me. Here is the
> code.
>
> #include <iostream>
> struct A
> {
> A(){} // not trivial
> ~A(){}
> void f1()const
> {
> std::cout << this << '\n';
> }
> void f2(this const A& self)
> {
> std::cout << &self << '\n';
> }
> };
>
> void f3(const A& a)
> {
> std::cout << &a << '\n';
> }
>
> int main()
> {
> A a{};
> a.~A();
> a.f1(); // UB!
> f3(a); // OK
> a.f2(); // UB or not?
> auto p = &A::f2;
> p(a); // UB or not?
> p = f3;
> p(a); // OK
> new(std::addressof(a))A{}; // OK
> }
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-01-04 21:29:26