A
Alan Johnson
From the standard 5.3.5/5:
"If the object being deleted has incomplete class type at the point of
deletion and the complete class has a non-trivial destructor or a
deallocation function, the behavior is undefined."
In the program below, what constitutes "point of deletion"? Presumably,
since delete is called somewhere within shared_ptr's template, the point
of deletion is the same place at which the template is instantiated.
Does the following program therefore exhibit undefined behavior, or am I
missing something? (Does this generalize to all cases in which a
shared_ptr is created from a forward reference?)
#include <iostream>
#include <boost/shared_ptr.hpp>
// Forward reference.
class A ;
// A has incomplete type here.
boost::shared_ptr<A> pa ;
class A
{
public:
A() { std::cout << "A()" << std::endl ; }
~A() { std::cout << "~A()" << std::endl ; }
} ;
int main()
{
pa.reset(new A) ;
}
"If the object being deleted has incomplete class type at the point of
deletion and the complete class has a non-trivial destructor or a
deallocation function, the behavior is undefined."
In the program below, what constitutes "point of deletion"? Presumably,
since delete is called somewhere within shared_ptr's template, the point
of deletion is the same place at which the template is instantiated.
Does the following program therefore exhibit undefined behavior, or am I
missing something? (Does this generalize to all cases in which a
shared_ptr is created from a forward reference?)
#include <iostream>
#include <boost/shared_ptr.hpp>
// Forward reference.
class A ;
// A has incomplete type here.
boost::shared_ptr<A> pa ;
class A
{
public:
A() { std::cout << "A()" << std::endl ; }
~A() { std::cout << "~A()" << std::endl ; }
} ;
int main()
{
pa.reset(new A) ;
}