You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not very clear how to apply [basic.life] p7.2 and [basic.life] p8.2 when the non-static member function is an explicit object member function whose object parameter type is weird, and the function is called via a function pointer.
Consider the following example (Godbolt link; note that constructing a T from a non-living S can be well-defined per CWG453).
structS;
structT {
constexprT(const S&) {} // The parameter can references a non-living object as clarified in CWG453.
};
structS {
constexprvoidfun(this T) {}
};
static_assert([]{
constexprauto funptr = &S::fun;
union U { S s; } u; // u.s is inactive.
{
u.s.fun(); // #1
}
{
funptr(u.s); // #2
}
{
funptr(T{u.s}); // #3
}
returntrue;
}());
It seems that #1, #2, and #3 perform equivalent operations. However,
[basic.life] p8.2 perhaps indicates that #1 is UB (although implementations accept it in constant evaluation);
#2 has no formally object argument, and it's unclear whether u.s can be treated as the object argument;
there doesn't seem any object argument (of type S) in #3, and #3 seems well-defined.
Even when the object parameter type is conventional, e.g. in (the simplified version of) the example in the original thread:
structA {
A(){} // not trivial~A(){}
voidf2(thisconst A&);
};
intmain() {
A a{};
a.~A();
a.f2(); // UB or not?auto p = &A::f2;
p(a); // UB or not?new(std::addressof(a))A{}; // OK
}
It doesn't seem very clear that p(a) raises UB.
Suggested resolution:
The text was updated successfully, but these errors were encountered:
frederick-vs-ja
changed the title
[basic.life] Calling an explicit object member functions with a function pointer and an out-of-lifetime object
[basic.life] Calling an explicit object member function with a function pointer and an out-of-lifetime object
Feb 6, 2025
Full name of submitter (unless configured in github; will be published with the issue): Jiang An, Li Qiuyi
Reference (section label): [basic.life]
Link to reflector thread (if any):
https://lists.isocpp.org/std-proposals/2025/01/11954.php
Issue description:
It's not very clear how to apply [basic.life] p7.2 and [basic.life] p8.2 when the non-static member function is an explicit object member function whose object parameter type is weird, and the function is called via a function pointer.
Consider the following example (Godbolt link; note that constructing a
T
from a non-livingS
can be well-defined per CWG453).It seems that
#1
,#2
, and#3
perform equivalent operations. However,#1
is UB (although implementations accept it in constant evaluation);#2
has no formally object argument, and it's unclear whetheru.s
can be treated as the object argument;S
) in#3
, and#3
seems well-defined.Even when the object parameter type is conventional, e.g. in (the simplified version of) the example in the original thread:
It doesn't seem very clear that
p(a)
raises UB.Suggested resolution:
The text was updated successfully, but these errors were encountered: