C++ Logo


Advanced search

Subject: Re: [std-proposals] P0466: about the danger of type parameters deduced by &C::m
From: Marcin Jaczewski (marcinjaczewski86_at_[hidden])
Date: 2020-12-05 19:06:17

sob., 5 gru 2020 o 16:19 Kazutoshi Satoda via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
> On 2020/12/05 23:59 +0900, Arthur O'Dwyer wrote:
> > If there's something in this vicinity to improve the safety and
> > teachability of C++, I'd look harder at the idea that &C::b is sometimes
> > *not* of type (T C::*). That seems like a construct that would come up
> > (handwave) 100x more commonly than `is_pointer_interconvertible_with_class`
> > -- which is still far from common, but at least it'd be nice to fix, or at
> > least figure out a specific reason why we can't.
> >
> > (Even if we could fix the type of &C::b, that's still an extremely uncommon
> > construct, and it might not be worth fixing -- just wall up that part of the
> > language and never talk about it again. ;))
> FYI, from the paper:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0466r5.pdf
> > The awkwardness of the deduced type of pointer-to-member constants was
> > discussed in core language issue 203; no action was taken for fear of
> > breaking existing code.
> https://wg21.cmeerw.net/cwg/issue203
> > Additional note, April, 2015:
> > EWG has determined that the utility of such a change is outweighed by
> > the fact that it would break code. See EWG issue 89.
> https://cplusplus.github.io/EWG/ewg-closed.html#89
> > Discussed in Rapperswil 2014. EWG thought that the change to existing
> > semantics would practically require a time machine, and noted that
> > these semantics didn't appear by accident. Changing the semantics was
> > estimated to break too much existing code, so closing as NAD.

Ok, this is impossible but could we alter language to allow accessing
this in another way?
If I recall correctly there is no defined `+` operator for member
pointers, and could we define it to allow this? e.g.
&A::f + &F::i // member pointer to `&a.f.i`
&A::D // offset to base
&A::D + &D::C + &C::i // pointer from `A` to member `i` of base `C` of base `D`

we could even replace some static cast using:
pa + &A::B + &B::C // similar to `static_cast<C*>(pa)`, work even if
`A` have multiple bases `C`

and if `-` will be defined then:
A* pa;
M* pm = pa + &A::m;
assert(pa == pm - &A::m); //UB if `pm` was not member `m` of some `A`

Everything will be strong typed, you can't add `&A::m + &A::m` or
`&A::b + &C::i` if `b` is not `C` type.

> --
> k_satoda
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups