Title
POD-structs with template assignment operators
Status
nad
Section
11.2 [class.prop]
Submitter
Alisdair Meredith

Created on 2005-03-19.00:00:00 last changed 10 hours ago

Messages

Date: 2025-10-15.00:00:00

Additional notes (October, 2025)

Updated the issue description to refer to the current term "trivially copyable" instead of "POD".

Closing as NAD at the suggestion of the issue submitter; it is intentional that special member function templates are not considered for the definition of "trivially copyable", even though they might be selected by overload resolution during copy or move operations.

Date: 2025-10-26.11:47:31

A trivially copyable class is not permitted to have a user-declared copy assignment operator (11.2 [class.prop] paragraph 1). However, a template assignment operator is not considered a copy assignment operator, even though its specializations can be selected by overload resolution for performing copy operations (11.4.6 [class.copy.assign] paragraph 12). Consequently, X in the following code is trivially copyable notwithstanding the fact that copy assignment (for a non-const operand) is a member function call rather than a bitwise copy:

    struct X {
      template<typename T> const X& operator=(T&);
    };
    void f() {
      X x1, x2;
      x1 = x2;  // calls X::operator=<X>(X&)
    }

Is this intentional?

History
Date User Action Args
2025-10-26 11:47:31adminsetmessages: + msg8178
2025-10-26 11:47:31adminsetstatus: open -> nad
2005-03-19 00:00:00admincreate