[PATCH] D57626: Disallow trivial_abi on a class if all copy and move constructors are deleted

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 3 07:55:52 PST 2019


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





More information about the cfe-commits mailing list