dblaikie added a comment.

In D90719#2376388 <https://reviews.llvm.org/D90719#2376388>, @rnk wrote:

> In D90719#2372656 <https://reviews.llvm.org/D90719#2372656>, @dblaikie wrote:
>
>> My understanding is that such code is UB, is that right?
>
> I guess I'm not convinced it's UB, and need some language lawyering help to 
> decide.

Fair enough. The code we're talking about essentially boils down to this, right:

  struct non_trivially_constructible {
    non_trivially_constructible();
    int i;
  };
  struct implicitly_non_trivially_constructible : non_trivially_constructible {
  };
  void f1() {
    using T = implicitly_non_trivially_constructible;
    alignas(T) unsigned char data[sizeof(T)];
    T* t = static_cast<T*>(&data);
    t->i = 3;
    ...
  }

Yeah? My understanding is that the lifetime of the T object hasn't started, 
because its ctor hasn't been run. For trivial types that's a bit fuzzier (eg: 
`int *i = (int*)malloc(sizeof(int)); *i = 3;` - we don't usually bother to call 
the pseudodestructor on this type) but for a non-trivially constructible thing, 
I'd think that was pretty well required/guaranteed by the language? (sort of by 
definition of non-trivially constructible)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90719/new/

https://reviews.llvm.org/D90719

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to