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

            Bug ID: 92143
           Summary: std::pmr::polymorphic_allocator<char> throws bad_alloc
                    on macOS
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugzilla at daryl dot haresign.com
  Target Milestone: ---

The following code throws a std::bad_alloc on macOS (seen via GCC 9.2 installed
with Homebrew, on macOS Catalina 10.15):

  #include <memory_resource>
  #include <string>
  int main()
  {
    std::pmr::string s { "0123456789abcdef" };
  }

16 characters is required to get it to overflow SSO.

The same issue can be seen with the following code:

  #include <memory_resource>
  int main()
  {
    std::pmr::polymorphic_allocator<char> alloc {
      std::pmr::new_delete_resource()
    };
    alloc.allocate(1);
  }

Changing the type from char to short, and char to int, yields the same error. 
Once you get to long, it starts working.

Presumably power-of-two alignments less than sizeof(void *) are not supported
(that's certainly what posix_memalign says).

Looking through the wording, it's all down to a question of whether
[mem.res.private] p2 allows for your memory resources to force the alignment to
be at least alignof(void *).  I would say the answer is probably yes.

http://eel.is/c++draft/mem.res#private-2

Reply via email to