views:

428

answers:

3

Of course, warning must be treated, but why is VC++ C4150 (deletion of pointer to incomplete type) only a warning?

+2  A: 

You get this warning as result of forward declaration. So compiler has recognized that it is structure/class, but not sure about invocation of destructor.

Sense of warning most possible is concerned with second pass of code analyze by msvc. When latter class is resolved compiler can make a decision if destructor exists.

Dewfy
+1  A: 

It is legal in C++, even though often enough a bad idea.

Roughly, Warning Level 1 are of the "you might be surrised, but I ignored what you said there" type, and a few selected statements where the generated code is very likely incorrect and crash-prone.

So WL 2 is appropriate, since it is legal and in many scenarios totally ok to delete an incomplete type.

Of course, that reasoning is just an educated guess. Maybe Microsoft rolled the dice to assigne this warning level.

peterchen
+4  A: 

Because standard says it's legal, although dangerous: 5.3.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.

Tadeusz Kopec