In this code, the temporary inside_t instantiated in main() goes out of
scope by the time we hit the next line.
MSVC 2003 doesn't complain about that even at the highest warning level. Is
it legal? If so, why?
struct inside_t
{
};
struct outside_t
{
const inside_t& _inside;
outside_t(const inside_t& inside) : _inside(inside)
{
}
};
int main()
{
const outside_t& outside=outside _t(inside_t());
// now, outside._inside is referencing to nowhere
return 0;
}
scope by the time we hit the next line.
MSVC 2003 doesn't complain about that even at the highest warning level. Is
it legal? If so, why?
struct inside_t
{
};
struct outside_t
{
const inside_t& _inside;
outside_t(const inside_t& inside) : _inside(inside)
{
}
};
int main()
{
const outside_t& outside=outside _t(inside_t());
// now, outside._inside is referencing to nowhere
return 0;
}
Comment