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

--- Comment #33 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I've been working on this again, and I think that the resource_adaptor type is
the wrong place to fix the malloc alignment problem.

The correct fix is to adjust the value of __STDCPP_DEFAULT_NEW_ALIGNMENT__ on
targets where malloc doesn't agree with GCC's alignof(max_align_t). Otherwise
even if I make resource_adaptor work for those targets, this test will still
fail:

    #include <memory>
    #include <cstddef>
    #include <cstdint>
    #include <assert.h>

    template<typename T>
      inline bool aligned(void* p)
      { return (reinterpret_cast<std::uintptr_t>(p) % alignof(T)) == 0; }

    int
    main()
    {
      using test_type = std::max_align_t; // largest fundamental alignment
      std::allocator<test_type> a;
      for (int i = 0; i < 10; ++i)
      {
        test_type* p1 = a.allocate(1);
        VERIFY( aligned<test_type>(p1) );
        test_type* p2 = a.allocate(20);
        VERIFY( aligned<test_type>(p2) );
        a.deallocate(p1, 1);
        a.deallocate(p2, 20);
      }
    }

If we make std::allocator<max_align_t> work then the tests for resource_adaptor
will also work, at least on Solaris.

Reply via email to