diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-01-09 13:16:11 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-10-31 10:24:08 +0000 |
commit | 646b24efaa50b149c12d0ae432999cb5a0cd12f2 (patch) | |
tree | f2ac431e8e2f7be81c0037ec749d6fb94a9626e3 | |
parent | b39f62ff739e9ffea0e6485667f15b985f8cd63d (diff) | |
download | gcc-646b24efaa50b149c12d0ae432999cb5a0cd12f2.zip gcc-646b24efaa50b149c12d0ae432999cb5a0cd12f2.tar.gz gcc-646b24efaa50b149c12d0ae432999cb5a0cd12f2.tar.bz2 |
libstdc++: Add align_alloc attribute to aligned operator new
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.
Reviewed-by: Jakub Jelinek <jakub@redhat.com>
-rw-r--r-- | libstdc++-v3/libsupc++/new | 6 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/18_support/new_aligned_warn.cc | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/libstdc++-v3/libsupc++/new b/libstdc++-v3/libsupc++/new index e9a3d9b..43450300 100644 --- a/libstdc++-v3/libsupc++/new +++ b/libstdc++-v3/libsupc++/new @@ -167,7 +167,7 @@ void operator delete[](void*, const std::nothrow_t&) #if __cpp_aligned_new _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t) _GLIBCXX_TXN_SAFE - __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); + __attribute__((__externally_visible__, __alloc_size__ (1), __alloc_align__ (2), __malloc__)); _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) _GLIBCXX_TXN_SAFE _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); @@ -178,10 +178,10 @@ void operator delete(void*, std::align_val_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t) _GLIBCXX_TXN_SAFE - __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); + __attribute__((__externally_visible__, __alloc_size__ (1), __alloc_align__ (2), __malloc__)); _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) _GLIBCXX_TXN_SAFE - _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); + _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __alloc_align__ (2), __malloc__)); void operator delete[](void*, std::align_val_t) _GLIBCXX_TXN_SAFE _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); void operator delete[](void*, std::align_val_t, const std::nothrow_t&) diff --git a/libstdc++-v3/testsuite/18_support/new_aligned_warn.cc b/libstdc++-v3/testsuite/18_support/new_aligned_warn.cc new file mode 100644 index 0000000..e9d374a --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/new_aligned_warn.cc @@ -0,0 +1,13 @@ +// { dg-options "-Wattributes" } +// { dg-do compile { target c++17 } } + +#include <new> + +int main() +{ + // PR c++/86878 has a patch to make these warn. + (void) operator new(1, std::align_val_t(3)); // { dg-warning "power of two" "" { xfail *-*-* } } + (void) operator new[](1, std::align_val_t(10)); // { dg-warning "power of two" "" { xfail *-*-* } } + (void) operator new(1, std::align_val_t(0), std::nothrow_t()); // { dg-warning "power of two" "" { xfail *-*-* } } + (void) operator new[](1, std::align_val_t(-1), std::nothrow_t()); // { dg-warning "power of two" "" { xfail *-*-* } } +} |