+2013-09-09 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/43452
+ * doc/invoke.texi (-Wdelete-incomplete): Document it.
+
2013-09-09 Ian Bolton <ian.bolton@arm.com>
* config/aarch64/aarch64.c (aarch64_preferred_reload_class): Return
* config/aarch64/aarch64.c (aarch64_select_cc_mode): Return CC_SWP for
comparison with negated operand.
- * config/aarch64/aarch64.md (compare_neg<mode>): Match canonical RTL form.
+ * config/aarch64/aarch64.md (compare_neg<mode>): Match canonical
+ RTL form.
2013-09-09 Richard Biener <rguenther@suse.de>
+2013-09-09 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/43452
+ * c.opt (Wdelete-incomplete): Add.
+
2013-09-08 Joern Rennecke <joern.rennecke@embecosm.com>
* c-common.c (same_scalar_type_ignoring_signedness): Delete.
C ObjC Var(warn_declaration_after_statement) Warning
Warn when a declaration is found after a statement
+Wdelete-incomplete
+C++ ObjC++ Var(warn_delete_incomplete) Init(1) Warning
+Warn when deleting a pointer to incomplete type
+
Wdelete-non-virtual-dtor
C++ ObjC++ Var(warn_delnonvdtor) Warning LangEnabledBy(C++ ObjC++,Wall)
Warn about deleting polymorphic objects with non-virtual destructors
+2013-09-09 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/43452
+ * init.c (build_vec_delete_1): When the type is incomplete emit a
+ warning, enabled by default (not an error).
+ (build_delete): Adjust to use OPT_Wdelete_incomplete.
+
2013-09-09 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58362
{
tree virtual_size;
tree ptype = build_pointer_type (type = complete_type (type));
- tree size_exp = size_in_bytes (type);
+ tree size_exp;
/* Temporary variables used by the loop. */
tree tbase, tbase_init;
if (base == error_mark_node || maxindex == error_mark_node)
return error_mark_node;
+ if (!COMPLETE_TYPE_P (type))
+ {
+ if ((complain & tf_warning)
+ && warning (OPT_Wdelete_incomplete,
+ "possible problem detected in invocation of "
+ "delete [] operator:"))
+ {
+ cxx_incomplete_type_diagnostic (base, type, DK_WARNING);
+ inform (input_location, "neither the destructor nor the "
+ "class-specific operator delete [] will be called, "
+ "even if they are declared when the class is defined");
+ }
+ return build_builtin_delete_call (base);
+ }
+
+ size_exp = size_in_bytes (type);
+
if (! MAYBE_CLASS_TYPE_P (type) || TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
goto no_destructor;
if (!COMPLETE_TYPE_P (type))
{
if ((complain & tf_warning)
- && warning (0, "possible problem detected in invocation of "
+ && warning (OPT_Wdelete_incomplete,
+ "possible problem detected in invocation of "
"delete operator:"))
{
cxx_incomplete_type_diagnostic (addr, type, DK_WARNING);
- inform (input_location, "neither the destructor nor the class-specific "
+ inform (input_location,
+ "neither the destructor nor the class-specific "
"operator delete will be called, even if they are "
"declared when the class is defined");
}
-Wno-attributes -Wno-builtin-macro-redefined @gol
-Wc++-compat -Wc++11-compat -Wcast-align -Wcast-qual @gol
-Wchar-subscripts -Wclobbered -Wcomment -Wconditionally-supported @gol
--Wconversion -Wcoverage-mismatch -Wno-cpp -Wno-deprecated @gol
--Wno-deprecated-declarations -Wdisabled-optimization @gol
+-Wconversion -Wcoverage-mismatch -Wdelete-incomplete -Wno-cpp @gol
+-Wno-deprecated -Wno-deprecated-declarations -Wdisabled-optimization @gol
-Wno-div-by-zero -Wdouble-promotion -Wempty-body -Wenum-compare @gol
-Wno-endif-labels -Werror -Werror=* @gol
-Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
Warn when a literal '0' is used as null pointer constant. This can
be useful to facilitate the conversion to @code{nullptr} in C++11.
+@item -Wdelete-incomplete @r{(C++ and Objective-C++ only)}
+@opindex Wdelete-incomplete
+@opindex Wno-delete-incomplete
+Warn when deleting a pointer to incomplete type, which may cause
+undefined behavior at runtime. This warning is enabled by default.
+
@item -Wuseless-cast @r{(C++ and Objective-C++ only)}
@opindex Wuseless-cast
@opindex Wno-useless-cast
// PR c++/19811
-class C; // { dg-error "forward" }
+class C; // { dg-warning "forward" }
void foo(void *p) {
- delete [] ((C*)p) ; // { dg-error "" }
+ delete [] ((C*)p) ; // { dg-warning "problem|incomplete" }
}
--- /dev/null
+// PR c++/43452
+
+class Foo; // { dg-warning "forward" }
+int main() {
+ Foo* p; // { dg-warning "incomplete" }
+ delete [] p; // { dg-warning "problem" }
+}
--- /dev/null
+// PR c++/43452
+// { dg-options -Wno-delete-incomplete }
+
+class Foo;
+int main() {
+ Foo* p;
+ delete [] p;
+}