Is C++'s Flexible Array Members UB?

Does the above code lead to Undefined Behavior when used in C++? According to [ISO C++] flexible array members are not allowed, however the code appears to be a workaround for this limitation. Is it safe to use?

struct Foo {
  size_t len;
  size_t cap;
  char* buf() { return reinterpret_cast<char*>(this + 1); }
};

Foo* new_foo(size_t sz) {
  Foo* foo = reinterpret_cast<Foo*>(malloc(sz + sizeof(Foo)));
  foo->len = 0;
  foo->cap = sz;
  return foo;
}

Yes, the above code does lead to Undefined Behavior when used in C++. The use of a flexible array member in the Foo struct violates the rules of C++. Although this code may appear to be a workaround for the limitation, it is not safe to use.