[Bug c++/93790] New: Cannot initialize reference from std::reference_wrapper using direct- or list-initialization syntax in GCC 10 c++2a mode
mkrupcale at matthewkrupcale dot com
gcc-bugzilla@gcc.gnu.org
Mon Feb 17 18:50:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93790
Bug ID: 93790
Summary: Cannot initialize reference from
std::reference_wrapper using direct- or
list-initialization syntax in GCC 10 c++2a mode
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mkrupcale at matthewkrupcale dot com
Target Milestone: ---
The following results in a compile error in GCC 10 -std=c++2a mode[1]:
=======================================
struct S {};
class S_refwrap {
S& Sref_;
public:
S_refwrap(S& Sref) : Sref_(Sref) {}
operator S&() { return Sref_; }
};
S s;
S_refwrap s_rw(s);
S& s_r(s_rw);
=======================================
$ g++ --version
g++ (GCC) 10.0.1 20200216 (Red Hat 10.0.1-0.8)
$ g++ -std=c++2a -c /tmp/test1.cpp
/tmp/test1.cpp:11:12: error: invalid initialization of non-const reference of
type ‘S&’ from an rvalue of type ‘<brace-enclosed initializer list>’
11 | S& s_r(s_rw);
| ^
This does not result in an error in c++17 mode or with GCC 9.2 in c++2a mode.
However, using list-initialization with GCC 9.2 in c++2a mode does result in
the same error.
I originally encountered this when trying to initialize a reference from a
std::reference_wrapper using direct initialization. This also failed with
list-initialization but works with copy initialization (i.e. S& s_r = s_rw;).
The error with a constant reference is similar:
error: invalid initialization of reference of type ‘const S&’ from expression
of type ‘<brace-enclosed initializer list>’
This might be related to the following bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63604
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67259
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875
[1] https://godbolt.org/z/4udMyJ
More information about the Gcc-bugs
mailing list