boostorg / core

Boost Core Utilities
132 stars 86 forks source link

`boost::allocator_destroy()` emitting deprecated warnings for `std::pmr::polymorphic_allocator` in Clang 18.1.0 with C++20 #168

Closed k3DW closed 3 months ago

k3DW commented 3 months ago
#include <boost/core/allocator_access.hpp>
#include <memory_resource>

int main()
{
    std::pmr::polymorphic_allocator<int> alloc;

    int* p = boost::allocator_allocate(alloc, 1);
    boost::allocator_destroy(alloc, p);
}

Compiled in x86-64 clang 18.1.0 with -std=c++20 -Werror

https://godbolt.org/z/seqWTr8zj

/opt/compiler-explorer/libs/boost_1_84_0/boost/core/allocator_access.hpp:567:7: error: 'destroy<int>' is deprecated: use 'allocator_traits::destroy' instead [-Werror,-Wdeprecated-declarations]
  567 |     a.destroy(p);
      |       ^
pdimov commented 3 months ago

I wonder why it only warns under Clang 18 using libstdc++ 13.2.0, but not under GCC 13.2.0 itself, or under Clang 17 (which also uses libstdc++ 13).

k3DW commented 3 months ago

The "allocator_access.hpp" header already has this and its corresponding "pop".

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4996)
#endif

I suggest changing it to this, which looks similar to other places in the library.

#if defined(__clang__) && defined(__has_warning)
# if __has_warning("-Wdeprecated-declarations")
#  pragma clang diagnostic push
#  pragma clang diagnostic ignored "-Wdeprecated-declarations"
# endif
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4996)
#elif defined(__GNUC__) && !(defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

Link to my suggested changes