On Wed, Oct 30, 2024 at 09:24:05PM +0000, Jonathan Wakely wrote:
> The aligned versions of operator new should use the align_alloc
> attribute to help the compiler.
>
> PR c++/86878 requests that the compiler would use the attribute to warn
> about invalid attributes, so an XFAILed test is added for that.
>
> libstdc++-v3/ChangeLog:
>
> * libsupc++/new (operator new): Add attribute align_alloc(2) to
> overloads taking a std::align_val_t argument.
> * testsuite/18_support/new_aligned_warn.cc: New test.
> ---
> I think this makes sense, but maybe there's some property of the
> attribute that means this isn't a good idea? I think the compiler can
> use the value of align_val_t even though it's a scoped enumeration type.
We document that alloc_align (and alloc_size etc.) arguments can have
integer or enumerated types, the implemented check is INTEGRAL_TYPE_P (t)
&& TREE_CODE (t) != BOOLEAN_TYPE.
And the meaning of the attribute is exactly what the C++ standard requires
from such operators, so the patch LGTM.
Jakub