Title
template<class X> constexpr complex& operator=(const complex<X>&) has no specification
Status
wp
Section
[complex]
Submitter
Daniel Krügler

Created on 2023-05-21.00:00:00 last changed 10 months ago

Messages

Date: 2023-06-19.14:50:03

Proposed resolution:

This wording is relative to N4950.

  1. Add a new prototype specification between the current paragraphs 8 and 9 of [complex.member.ops] as indicated:

    [Drafting note: Similar to the proposed wording for LWG 3934, the wording form used below intentionally deviates from the rest of the [complex.member.ops] wording forms, because it seems much simpler and clearer to follow the wording forms used that specify the effects of imag and real functions plus borrowing relevant parts from [complex.members] p2.]

    constexpr complex& operator/=(const T& rhs);
    

    […]

    template<class X> constexpr complex& operator=(const complex<X>& rhs);
    

    -?- Effects: Assigns the value rhs.real() to the real part and the value rhs.imag() to the imaginary part of the complex value *this.

    -?- Returns: *this.

    template<class X> constexpr complex& operator+=(const complex<X>& rhs);
    

    […]

Date: 2023-06-17.00:00:00

[ 2023-06-17 Approved at June 2023 meeting in Varna. Status changed: Voting → WP. ]

Date: 2023-06-15.00:00:00

[ 2023-06-01; Reflector poll ]

Set status to Tentatively Ready after eight votes in favour during reflector poll.

Date: 2023-05-21.00:00:00

The class template complex synopsis in [complex] shows the following member function template:

template<class X> constexpr complex& operator= (const complex<X>&);

but does not specify its semantics. This affects a code example such as the following one:

#include <complex>

int main()
{
  std::complex<double> zd(1, 1);
  std::complex<float> zf(2, 0);
  zd = zf;
}

This problem exists since the 1998 version of the standard (at that time this was declared in subclause [lib.complex]), and even though this looks like a "copy-assignment-like" operation, its effects aren't implied by our general [functions.within.classes] wording (a function template is never considered as copy assignment operator, see [class.copy.assign]).

It should be point out that the refactoring done by P1467R9 had caused some other members to become finally specified that were not specified before, but in addition to LWG 3934's observation about the missing specification of the assignment operator taking a value type as parameter, this is now an additional currently unspecified member, but unaffected by any decision on LWG 3933.

History
Date User Action Args
2023-06-19 14:50:03adminsetmessages: + msg13656
2023-06-19 14:50:03adminsetstatus: voting -> wp
2023-06-12 08:52:25adminsetstatus: ready -> voting
2023-06-01 14:03:29adminsetmessages: + msg13596
2023-06-01 14:03:29adminsetstatus: new -> ready
2023-05-21 10:39:00adminsetmessages: + msg13553
2023-05-21 00:00:00admincreate