PING [PATCH] teach compute_objsize about placement new (PR 100876)
Wed Jun 9 15:47:13 GMT 2021
On 6/2/21 3:40 PM, Martin Sebor wrote:
> The two forms of placement operator new defined in <new> return their
> pointer argument and may not be displaced by user-defined functions.
> But because they are ordinary (not built-in) functions this property
> isn't reflected in their declarations alone, and there's no user-
> level attribute to annotate them with. When they are inlined
> the property is transparent in the IL but when they are not (without
> inlining such as -O0), calls to the operators appear in the IL and
> cause -Wmismatched-new-delete to try to match them with the functions
> called to deallocate memory. When the pointer to the memory was
> obtained from a function that matches the deallocator but not
> the placement new, the warning falsely triggers.
> The attached patch solves this by detecting calls to placement new
> and treating them the same as those to other pass-through calls (such
> as memset). In addition, it also teaches -Wfree-nonheap-object about
> placement delete, for a similar reason as above. Finally, it also
> adds a test for attribute fn spec indicating a function returns its
> argument. It's not necessary for the fix (I had initially though
> placement new might have the attribute) but it seems appropriate
> to check.
> Tested on x86_64-linux.
More information about the Gcc-patches