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

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
As a workaround until the warning is made smarter, partial specialization can
be used to avoid the compile-time conditional, for example like so:

struct Test {
  char buf[4];

  template<typename T, bool>
  struct Ctor {
    static T *construct(void*) {
      return new T;  // else make it on the heap
    }
  };

  template<typename T> T* construct () {
    return Ctor<T, sizeof (T) <= sizeof Test::buf>::construct (buf);
  }
};

template<typename T> 
struct Test::Ctor<T, true> {
  static T* construct (void *p) {
    return new (p) T;
  }
};

Reply via email to