https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127279
Bug ID: 127279
Summary: Direct init of member reference disregards explicit
conversions
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pj at patrickjohnston dot org
Target Milestone: ---
Testcase:
struct S
{
int t{};
explicit operator int&()
{
return t;
}
};
struct Wrapper
{
int& t;
template<typename T>
Wrapper(T&& tt)
: t(tt)
{}
};
int main()
{
S s;
int& x(s);
Wrapper w(s);
}
Live: https://godbolt.org/z/qqvE9nKP8
GCC correctly initialises `x` using `S::operator int`, but fails to initialise
`Wrapper::t`, which should have the same initialisation semantics
Init semantics I believe are
https://eel.is/c++draft/dcl.init.general#15.2
-> https://eel.is/c++draft/dcl.init.ref#5.1.2
-> https://eel.is/c++draft/over.match.ref
and then it's direct init because https://eel.is/c++draft/dcl.init.general#14.1
This issue doesn't appear to occur when initialising a non-reference type.