While many warning messages have a way to control their emission and treatment, e.g. "warning: multi-line comment [-Wcomment]", some warnings do not, in particular: warning: possible problem detected in invocation of delete operator: [enabled by default] warning: 'value' has incomplete type [enabled by default] As a consequence of being enabled by default, there does not seem to be an associated warning class that I could pass to "-Werror=". I'd really like to be able to say "-Werror=delete-with-incomplete-type"
This option is very important, because this warning allowed us to fix one serious leak in our application. And to prevent this problem to reappear in the future we want to force this warning to be error, but unfortunately we are not able when building with GCC. All other compilers we use have this feature. And btw in clang the option is named -Wdelete-incomplete, so you can reuse it to minimize the difference between the compilers. BTW: Do someone has an explanation why this is allowed in the standard?
(In reply to Teodor Petrov from comment #1) > BTW: Do someone has an explanation why this is allowed in the standard? Because it's only a problem if the type has a non-trivial destructor or an overloaded operator delete. For a type with a trivial destructor (such as a POD) all that needs to be done is deallocate the memory. The standard says: "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." Since the compiler can't know if an incomplete type has a trivial destructor or not, it can only warn, not give a hard error. If you want to make it a hard error in your own program you should be able to, so confirming.
Actually it looks as though -Wdelete-incomplete is already supported *** This bug has been marked as a duplicate of bug 43452 ***
@Jonathan Wakely: Do you think the ISO C++ standard people will be willing to change this behaviour for a future standard? I'm asking in order to know if there is any point in starting a conversation with them.
That change would force compilers to reject currently valid programs that have well-defined behaviour. Changes that like are not popular. It is valid in C to pass a pointer to an incomplete type to free(), and this C++ rule is compatible. You can delete incomplete types if they have trivial destructors (like C structs).
I disagree with the assessment of this bug as a duplicate of bug 43452. That bug was resolved by the creation of the -Wdelete-incomplete option, upon which this bug depends. But this one requests the ability to make this warning into a fatal error, i.e. the creation of a -Werror=delete-incomplete option, which does not exist yet. Please could you consider reopening this bug and marking it as not a duplicate?
(In reply to Chris Wilson from comment #6) > I disagree with the assessment of this bug as a duplicate of bug 43452. That > bug was resolved by the creation of the -Wdelete-incomplete option, upon > which this bug depends. But this one requests the ability to make this > warning into a fatal error, i.e. the creation of a -Werror=delete-incomplete > option, which does not exist yet. Of course it exists. -Werror=foo is valid for any -Wfoo warning, and it's trivial to check that it works.