This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/36430] New: Cannot convert a temporary to a non-const reference even with conversion operator


struct Foo {
    operator Foo & () { return *this; }
};
void frobnicate(Foo &) {
/* in reality, the Foo is changed here and returned */
}
int main () {
    frobnicate (Foo());
}

temporary.cpp:8: error: invalid initialization of non-const reference of type
?Foo&? from a temporary of type ?Foo?
temporary.cpp:4: error: in passing argument 1 of ?void frobnicate(Foo&)?

This works with g++ 4.1, but does not work with 4.2 and 4.3.


-- 
           Summary: Cannot convert a temporary to a non-const reference even
                    with conversion operator
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gbrammer at gmx dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36430


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]