On Friday 25 October 2013 10:25:16 Giovanni Piero Deretta wrote:
On Fri, Oct 25, 2013 at 10:22 AM, Oliver Kowalke
wrote: 2013/10/25 Giovanni Piero Deretta
Intrusive_ptr doesn't have tivial copy constructor (how could it have? it needs to update the counter), ergo is not trivially copyable and the
above
two point do not apply.
but the standard says 'trivially copyable' not 'trivial copy constructor' - e.g. the code examples by the standard document gives correct results for intrusive_ptr (because all criteria are fulfilled). does this mean the standard document contains a false wording/examples?
I do not have the standard at hand, but a trivially copyable class is a class that: 1. Has no non-trivial copy constructors (this also requires no virtual functions or virtual bases)
2. Has no non-trivial move constructors
3. Has no non-trivial copy assignment operators
4. Has no non-trivial move assignment operators
5. Has a trivial destructor
[from cppreference.com, which may or may not be authoritative]
You are correct, I'll just provide some references: Trivially copyable types are defined in 3.9/9 [basic.types]. [...] Scalar types, trivially copyable class types (Clause 9), arrays of such types, and cv-qualified versions of these types (3.9.3) are collectively called trivially copyable types. [...] Trivially copyable class types are defined in 9/6 [class]. A trivially copyable class is a class that: — has no non-trivial copy constructors (12.8), — has no non-trivial move constructors (12.8), — has no non-trivial copy assignment operators (13.5.3, 12.8), — has no non-trivial move assignment operators (13.5.3, 12.8), and — has a trivial destructor (12.4). A trivial class is a class that has a trivial default constructor (12.1) and is trivially copyable. [ Note: In particular, a trivially copyable or trivial class does not have virtual functions or virtual base classes. — end note ]