public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100307] New: Wrong placement-new warning
@ 2021-04-28  6:52 s.rueckerl at tum dot de
  2021-04-28  9:31 ` [Bug c++/100307] [11/12 Regression] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: s.rueckerl at tum dot de @ 2021-04-28  6:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100307

            Bug ID: 100307
           Summary: Wrong placement-new warning
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: s.rueckerl at tum dot de
  Target Milestone: ---

A placement new warning is generated whenever the placement new is used with
in-line pointer arithmetic resulting in a negative offset to the original
pointers address. It does not fail with a positive offset or if the calculation
is done with a temporary variable before.

This did not happen with GCC-10 and can be observed with different GCC-11
versions (and the trunk version as provided on godbolt.org).

The following code replicates this behavior: (https://godbolt.org/z/nPGvEM44e)

```
#include <new>

static char myMemory [128];

int main()
{
    //make it fail
    char* memoryPtr = myMemory+32;
    int* myValue = new (memoryPtr - 1) int {42};

    //does not fail with positive offset
    char* secondMemoryPtr = myMemory+64;
    int* mySecondValue = new (secondMemoryPtr + 1) int {42};

    //does not fail with temporary
    char* thirdMemoryPtr = myMemory+96;
    char* placementNewAddress = thirdMemoryPtr - 1;
    int* myThirdValue = new (placementNewAddress) int {1};

    // use all variables for return value to avoid unused variable warnings
    return *myValue + *mySecondValue + *myThirdValue;
}
```

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-06-17 20:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28  6:52 [Bug c++/100307] New: Wrong placement-new warning s.rueckerl at tum dot de
2021-04-28  9:31 ` [Bug c++/100307] [11/12 Regression] " rguenth at gcc dot gnu.org
2021-04-28 10:10 ` jakub at gcc dot gnu.org
2021-04-28 15:55 ` [Bug middle-end/100307] [11/12 Regression] spurious -Wplacement-new with negative pointer offset msebor at gcc dot gnu.org
2021-04-29  1:14 ` msebor at gcc dot gnu.org
2021-05-04 19:51 ` cvs-commit at gcc dot gnu.org
2021-05-04 19:52 ` [Bug middle-end/100307] [11 " msebor at gcc dot gnu.org
2021-06-17 20:07 ` cvs-commit at gcc dot gnu.org
2021-06-17 20:09 ` 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).