-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Traits.h marks std::list as trivially relocatable, but in fact it is not #889
Comments
Hi Quuxplusone, Can you give us more information about how you reached your conclusion for std::list? The heap allocated nodes form a circular list; there is no pointer back to the list object itself. When the list has one element, for example, it points to itself. This is true in both libstdc++ and libc++. I don't know about std::function. Thanks, |
Hi Nathan, Right, the "circular" part of "circular list" is what causes the trouble. Contrast these two diagrams from P0773R0: The trick with
You can verify for yourself the memcpyability of
|
Thanks for the clarification, I was mistaken. |
@nbronson: I've got a relatively exhaustive list of "what's trivially relocatable and what's not" for libc++, here: https://github.com/Quuxplusone/libcxx/blob/trivially-relocatable/test/libcxx/type_traits/is_trivially_relocatable.pass.cpp I'd like to talk more via email and see if we can combine efforts. I'm coming around to the idea that the primary benefit of putting |
I would love to see some common way for library authors to mark their own types as trivially-relocatable. And to see encouragement for types to be trivially-relocatable, and library optimizations for types which are trivially-relocatable. Q: "trivially" modifies "relocatable" - what does it mean for a type to be relocatable but not trivially-relocatable? (Does a type being relocatable just mean it has both a destructor and a move-or-copy-constructor?) |
Could making relocation a first-class entity help with another problem we have, which is how to relocate a std::pair<const A,B> without copying the A (and without relying on a UB const_cast)? |
Yes, that's how my paper defines it. The operation in general is "relocation"; a type that supports relocation is "relocatable"; and if relocation is tantamount to memcpy then it's "trivially relocatable." (And yes that's a bit different from how Folly calls it, but I think it is more consistent with the other C++11 type traits.)
No, not as my paper defines it (because I don't really define it as a first-class entity). I'm not sure that we ought to be able to "relocate out of" |
Hi folks,
https://github.com/facebook/folly/blob/8fb5c15272a0dcdc/folly/Traits.h#L712 should be removed, as
std::list<T>
is never trivially relocatable on libstdc++ nor libc++. (The last heap-allocated element of the list holds a pointer into the list object itself;memcpy
ing the list will break this pointer.)Oh, and similarly, https://github.com/facebook/folly/blob/8fb5c15272a0dcdc/folly/Traits.h#L716 is wrong for at least libc++; I'm not sure about libstdc++.
Also, hi, this is Arthur O'Dwyer. I've got a WG21 proposal to standardize the Folly/EASTL/BSL notion of "trivially relocatable" into C++2a. I have wording and an implementation and everything. I am looking for coauthors, particularly coauthors who have been involved with the prior art in Folly. If you'd like to contribute and/or lend your support to P1144 Object relocation in terms of move plus destroy, please shoot me an email!
The text was updated successfully, but these errors were encountered: