Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/TriviallyCopyable"

From cppreference.com
< cpp‎ | named req
(Requirements: P0848R3)
(Apply the item "eligible" retroactively to old standard revisions)
Line 16: Line 16:
  
 
This implies that a trivially copyable class has no [[cpp/language/virtual|virtual functions]] or [[cpp/language/derived_class#Virtual_base_classes|virtual base classes]].
 
This implies that a trivially copyable class has no [[cpp/language/virtual|virtual functions]] or [[cpp/language/derived_class#Virtual_base_classes|virtual base classes]].
 +
 +
===Notes===
 +
Until C++20, a copy constructor, move constructor, copy assignment operator, or move assignment operator is eligible if and only if it is non-deleted.
  
 
===Defect reports===
 
===Defect reports===

Revision as of 22:09, 15 August 2020

 
 
C++ named requirements
 

Contents

Requirements

The following types are collectively called trivially copyable types:

  • Scalar types
  • Trivially copyable classes, i.e. classes satisfying following requirements:
    • At least one copy constructor, move constructor, copy assignment operator, or move assignment operator is eligible
    • Every eligible copy constructor (if any) is trivial
    • Every eligible move constructor (if any) is trivial
    • Every eligible copy assignment operator (if any) is trivial
    • Every eligible move assignment operator (if any) is trivial
    • Has a trivial non-deleted destructor
  • Arrays of TriviallyCopyable objects

This implies that a trivially copyable class has no virtual functions or virtual base classes.

Notes

Until C++20, a copy constructor, move constructor, copy assignment operator, or move assignment operator is eligible if and only if it is non-deleted.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
CWG 1734 C++11 C++03 POD with deleted non-trivial assignment was not trivial deleted ctors/operators allowed
CWG 2094 C++11 Volatile scalar types are not trivially copyable (CWG 1746) made trivially copyable

See also

checks if a type is trivially copyable
(class template) [edit]