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

--- Comment #4 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
And what about void pointers?  How is it assumed that the pointed to object is
read when it has no value?

Expanded example loosely rewritten from the original library code.
---
void GC_addRange(const void * const, __SIZE_TYPE__);

struct VoidArray
{
  __SIZE_TYPE__ length;
  void *ptr;
};

// struct Array(T) {
#define T int
bool isInitialized;
VoidArray _data;
__SIZE_TYPE__ _capacity;

void
reserve (__SIZE_TYPE__ elements)
{
  if (!isInitialized)
    {
      if (!elements) return;
      __SIZE_TYPE__ sz;
      int overflow = __builtin_mul_overflow (elements, sizeof (T), &sz);
      if (overflow) __builtin_abort ();
      void *p = __builtin_malloc (sz);
      if (!p) __builtin_abort ();
      // static if (hasIndirections!T) {
        GC_addRange (p, sz);
      // }
      _data.ptr = p;
      _data.length = 0;
      _capacity = elements;
    }
  else
    {
      // _data.reserve (elements);
    }
}

// };

Reply via email to