struct X {}; struct Y { const X& x; Y(const X& x) : x(x) {} }; int main() { Y y(X()); // here y.x "dangling" }
does not create a warning with -Wall or any other warning option I tried. However, binding a temporary value to a reference member seems to be doomed in any possible situation --- once the constructor has been executed, we get a dangling reference. So I believe that this situation could be included in -Wall, or at least there could be a special warning (especially since in all C++ books I have I didn't find any mentioning of the point, that temporaries used in the construction of an object will be destroyed as soon as the constructor is left, which is different from binding non-class-member-const-references to temporaries). -- Summary: no warning available when binding a temporary to a const reference member Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: o dot kullmann at swansea dot ac dot uk http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26471