public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/96511] New: Incorrect placement-new warning @ 2020-08-06 23:46 mserdarsanli at gmail dot com 2020-08-07 14:50 ` [Bug c++/96511] " msebor at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: mserdarsanli at gmail dot com @ 2020-08-06 23:46 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96511 Bug ID: 96511 Summary: Incorrect placement-new warning Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mserdarsanli at gmail dot com Target Milestone: --- Below code causes the warning in the last line, which seems to be incorrect. It affects all versions starting from GCC 8 Compiler explorer: https://godbolt.org/z/xhf6cr #include <new> struct Foo { Foo() = default; Foo(int _a) : a(_a) {} int a = 0; }; void f() { Foo arr[2]; new (arr) Foo(10); // ok new (arr + 0) Foo(10); // ok new (&arr[0]) Foo(10); // ok new (&arr[1]) Foo(15); // ok new (arr + 1) Foo(15); // warning: placement new constructing an object of type 'Foo' and size '4' in a region of type 'Foo [2]' and size '0' [-Wplacement-new=] } ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/96511] Incorrect placement-new warning 2020-08-06 23:46 [Bug c++/96511] New: Incorrect placement-new warning mserdarsanli at gmail dot com @ 2020-08-07 14:50 ` msebor at gcc dot gnu.org 2020-08-11 16:20 ` msebor at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: msebor at gcc dot gnu.org @ 2020-08-07 14:50 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96511 Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Known to fail| |10.2.0, 11.0, 8.4.0, 9.3.0 Status|UNCONFIRMED |NEW Last reconfirmed| |2020-08-07 CC| |msebor at gcc dot gnu.org --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed. To determine the final offset the warning multiplies the offset in a POINTER_PLUS expression by the elements size the same way it does the index in an ARRAY_REF expression. The latter is correct but the former isn't. A simplified test case: $ cat pr96511.C && gcc -S -Wall -Wextra pr96511.C void* operator new (__SIZE_TYPE__, void *p) { return p; } void g () { int a[2]; new (&a[0] + 1) int; } pr96511.C: In function ‘void g()’: pr96511.C:7:14: warning: placement new constructing an object of type ‘int’ and size ‘4’ in a region of type ‘int [2]’ and size ‘0’ [-Wplacement-new=] 7 | new (&a[0] + 1) int; | ~~~~~~^~~ ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/96511] Incorrect placement-new warning 2020-08-06 23:46 [Bug c++/96511] New: Incorrect placement-new warning mserdarsanli at gmail dot com 2020-08-07 14:50 ` [Bug c++/96511] " msebor at gcc dot gnu.org @ 2020-08-11 16:20 ` msebor at gcc dot gnu.org 2020-10-12 15:07 ` cvs-commit at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: msebor at gcc dot gnu.org @ 2020-08-11 16:20 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96511 Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org Status|NEW |ASSIGNED Keywords| |patch --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- Patch: https://gcc.gnu.org/pipermail/gcc-patches/2020-August/551783.html ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/96511] Incorrect placement-new warning 2020-08-06 23:46 [Bug c++/96511] New: Incorrect placement-new warning mserdarsanli at gmail dot com 2020-08-07 14:50 ` [Bug c++/96511] " msebor at gcc dot gnu.org 2020-08-11 16:20 ` msebor at gcc dot gnu.org @ 2020-10-12 15:07 ` cvs-commit at gcc dot gnu.org 2020-10-12 15:08 ` msebor at gcc dot gnu.org 2021-01-19 23:31 ` msebor at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2020-10-12 15:07 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96511 --- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>: https://gcc.gnu.org/g:de05c19d5fd661ae16dd75a895b49d32d12f5edc commit r11-3826-gde05c19d5fd661ae16dd75a895b49d32d12f5edc Author: Martin Sebor <msebor@redhat.com> Date: Fri Oct 9 13:56:53 2020 -0600 Correct handling of indices into arrays with elements larger than 1 (PR c++/96511) Resolves: PR c++/96511 - Incorrect -Wplacement-new on POINTER_PLUS into an array with 4-byte elements PR middle-end/96384 - bogus -Wstringop-overflow= storing into multidimensional array with index in range gcc/ChangeLog: PR c++/96511 PR middle-end/96384 * builtins.c (get_range): Return full range of type when neither value nor its range is available. Fail for ranges inverted due to the signedness of offsets. (compute_objsize): Handle more special array members. Handle POINTER_PLUS_EXPR and VIEW_CONVERT_EXPR that come up in front end code. (access_ref::offset_bounded): Define new member function. * builtins.h (access_ref::eval): New data member. (access_ref::offset_bounded): New member function. (access_ref::offset_zero): New member function. (compute_objsize): Declare a new overload. * gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Use enum special_array_member. * tree.c (component_ref_size): Use special_array_member. * tree.h (special_array_member): Define a new type. (component_ref_size): Change signature. gcc/cp/ChangeLog: PR c++/96511 PR middle-end/96384 * init.c (warn_placement_new_too_small): Call builtin_objsize instead of duplicating what it does. gcc/testsuite/ChangeLog: PR c++/96511 PR middle-end/96384 * g++.dg/init/strlen.C: Add expected warning. * g++.dg/warn/Wplacement-new-size-1.C: Relax warnings. * g++.dg/warn/Wplacement-new-size-2.C: Same. * g++.dg/warn/Wplacement-new-size-6.C: Same. * gcc.dg/Warray-bounds-58.c: Adjust * gcc.dg/Wstringop-overflow-37.c: Same. * g++.dg/warn/Wplacement-new-size-7.C: New test. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/96511] Incorrect placement-new warning 2020-08-06 23:46 [Bug c++/96511] New: Incorrect placement-new warning mserdarsanli at gmail dot com ` (2 preceding siblings ...) 2020-10-12 15:07 ` cvs-commit at gcc dot gnu.org @ 2020-10-12 15:08 ` msebor at gcc dot gnu.org 2021-01-19 23:31 ` msebor at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: msebor at gcc dot gnu.org @ 2020-10-12 15:08 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96511 Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Known to fail|11.0 | --- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> --- Fixed for GCC 11. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/96511] Incorrect placement-new warning 2020-08-06 23:46 [Bug c++/96511] New: Incorrect placement-new warning mserdarsanli at gmail dot com ` (3 preceding siblings ...) 2020-10-12 15:08 ` msebor at gcc dot gnu.org @ 2021-01-19 23:31 ` msebor at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: msebor at gcc dot gnu.org @ 2021-01-19 23:31 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96511 Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |11.0 Resolution|--- |FIXED Status|ASSIGNED |RESOLVED --- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> --- The patch is too intrusive to backport. Resolving as fixed. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-19 23:31 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-08-06 23:46 [Bug c++/96511] New: Incorrect placement-new warning mserdarsanli at gmail dot com 2020-08-07 14:50 ` [Bug c++/96511] " msebor at gcc dot gnu.org 2020-08-11 16:20 ` msebor at gcc dot gnu.org 2020-10-12 15:07 ` cvs-commit at gcc dot gnu.org 2020-10-12 15:08 ` msebor at gcc dot gnu.org 2021-01-19 23:31 ` msebor at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).