[cfe-dev] __is_trivially_copyable seems to be misbehaving

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Fri May 27 12:17:22 PDT 2016


Example:

  struct foo {
    foo(foo &&) = default;
    foo &operator=(foo &&) = default;
  };

  static_assert(__is_trivially_copyable(foo), "this really shouldn't be
true");

This static-assert succeeds, yet the code:

  void f(foo &x, foo &y) {
    x = y;
  }

fails.

This came up when someone on IRC tried to make a SmallVector of such things
and LLVM's isPodLike trait said "yes, this thing is podlike" and tried to
use std::copy to copy them around (& that was just luck that it failed - in
other places it used memcpy to copy them around, which would've been silent
badness). isPodLike is implemented in terms of __is_trivially_copyable,
where available. (granted, it's implemented in terms of is_class where
that's not available - so we don't have any code that /relies/ on the
correctness of __is_trivially_copyable, only for optimization purposes)

Am I seeing that right?

- Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160527/d81c3991/attachment.html>


More information about the cfe-dev mailing list