11 Aug
2015
11 Aug
'15
1:31 p.m.
2015-08-11 17:39 GMT+08:00 Stephan Bergmann
On 08/11/2015 10:27 AM, TONGARI J wrote:
template<class T> struct wrapper { wrapper() = default;
wrapper(boost::intrusive_ptr<T> const& p) : _p(p) {}
boost::intrusive_ptr<T> const& get_ptr() const { #if 0 // This is OK. if (_p) return _p; return nullptr; #else // Strange behavior. return _p ? _p : nullptr; #endif }
In both cases, you return a reference to a temporary, incurring undefined behavior.
Ah damn! You're right, how could I overlook the const& part!? Sorry for the noise.