Quuxplusone added a comment.

Can you give more intuition on why classes with no copy/move operations should 
be forced non-trivial-abi?  Let's take this specific example:

  struct [[clang::trivial_abi]] lock_guard {
      mutex *m;
      explicit lock_guard(mutex *m) : m(m) { m->lock(); }
      ~lock_guard() { m->unlock(); }
      lock_guard(const lock_guard&) = delete;
      lock_guard(lock_guard&&) = delete;
  };
  
  void foo(lock_guard g) { ... }
  void bar() { mutex m; foo(lock_guard(&m)); }

With C++17 "guaranteed copy elision," there's no reason this code would 
//need// copy/move operations. But equally I can't see any reason that `g` 
should not be passed in a register when possible — it's just a pointer, after 
all.
I admit that this `lock_guard` example is contrived and generally ill-advised 
<https://quuxplusone.github.io/blog/2018/11/12/parameter-lifetime-and-trivial-abi/>,
 but its ill-advisedness seems like a higher-level concern that shouldn't be 
"enforced" by fiddling with the rules of [[trivial_abi]], so I hope that's not 
what's going on here.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57626



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

Reply via email to