mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-17 18:00:55 +08:00
re PR c++/43452 (Array delete causes error on incomplete type)
2013-09-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/43452 * doc/invoke.texi (-Wdelete-incomplete): Document it. /c-family 2013-09-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/43452 * c.opt (Wdelete-incomplete): Add. /cp 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. /testsuite 2013-09-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/43452 * g++.dg/warn/Wdelete-incomplete-1.C: New. * g++.dg/warn/Wdelete-incomplete-2.C: Likewise. * g++.dg/init/delete1.C: Adjust. From-SVN: r202404
This commit is contained in:
parent
78d8b9f019
commit
c9b0866a1e
@ -1,3 +1,8 @@
|
||||
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
|
||||
@ -7,7 +12,8 @@
|
||||
|
||||
* 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>
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
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.
|
||||
|
@ -339,6 +339,10 @@ Wdeclaration-after-statement
|
||||
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
|
||||
|
@ -1,3 +1,10 @@
|
||||
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
|
||||
|
@ -3078,7 +3078,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
|
||||
{
|
||||
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;
|
||||
@ -3106,6 +3106,23 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
|
||||
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;
|
||||
|
||||
@ -3820,11 +3837,13 @@ build_delete (tree type, tree addr, special_function_kind auto_delete,
|
||||
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");
|
||||
}
|
||||
|
@ -240,8 +240,8 @@ Objective-C and Objective-C++ Dialects}.
|
||||
-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
|
||||
@ -4490,6 +4490,12 @@ types. @option{-Wconversion-null} is enabled by default.
|
||||
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
|
||||
|
@ -1,7 +1,7 @@
|
||||
// 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" }
|
||||
}
|
||||
|
7
gcc/testsuite/g++.dg/warn/Wdelete-incomplete-1.C
Normal file
7
gcc/testsuite/g++.dg/warn/Wdelete-incomplete-1.C
Normal file
@ -0,0 +1,7 @@
|
||||
// PR c++/43452
|
||||
|
||||
class Foo; // { dg-warning "forward" }
|
||||
int main() {
|
||||
Foo* p; // { dg-warning "incomplete" }
|
||||
delete [] p; // { dg-warning "problem" }
|
||||
}
|
8
gcc/testsuite/g++.dg/warn/Wdelete-incomplete-2.C
Normal file
8
gcc/testsuite/g++.dg/warn/Wdelete-incomplete-2.C
Normal file
@ -0,0 +1,8 @@
|
||||
// PR c++/43452
|
||||
// { dg-options -Wno-delete-incomplete }
|
||||
|
||||
class Foo;
|
||||
int main() {
|
||||
Foo* p;
|
||||
delete [] p;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user