Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7669691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:39:10+00:00 2026-05-31T15:39:10+00:00

This question comes from issues raised by this answer . Normally, we define copy

  • 0

This question comes from issues raised by this answer.

Normally, we define copy assignment operators for type T as T& operator=(const T&), and move assignment operators for type T as T& operator=(T&&).

However, what happens when we use a value parameter rather than a reference?

class T
{
public:
  T& operator=(T t);
};

This should make T both copy and move assignable. However, what I want to know is what are the language ramifications for T?

Specifically:

  1. Does this count as a copy assignment operator for T, according to the specification?
  2. Does this count as a move assignment operator for T, according to the specification?
  3. Will T have a compiler-generated copy assignment operator?
  4. Will T have a compiler-generated move assignment operator?
  5. How does this affect traits classes like std::is_move_assignable?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:39:11+00:00Added an answer on May 31, 2026 at 3:39 pm

    Most of this is described in §12.8. Paragraph 17 defines what counts as user-declared copy assignment operators:

    A user-declared copy assignment operator X::operator= is a non-static non-template member function of class X with exactly one parameter of type X, X&, const X&, volatile X&, or const volatile X&.

    Paragraph 19 defines what counts as user-declared move assignment operators:

    A user-declared move assignment operator X::operator= is a non-static
    non-template member function of class X with exactly one parameter of
    type X&&, const X&&, volatile X&&, or const volatile X&&.

    So, it counts as a copy assignment operator, but not as a move assignment operator.

    Paragraph 18 tells when the compiler generates copy assignment operators:

    If the class definition does not explicitly declare a copy assignment
    operator, one is declared implicitly. If the class definition declares
    a move constructor or move assignment operator, the implicitly
    declared copy assignment operator is defined as deleted; otherwise, it
    is defined as defaulted (8.4). The latter case is deprecated if the
    class has a user-declared copy constructor or a user-declared
    destructor.

    Paragraph 20 tells us when the compiler generates move assignment operators:

    If the definition of a class X does not explicitly declare a move
    assignment operator, one will be implicitly declared as defaulted if
    and only if
    […]
    — X does not have a user-declared copy assignment operator,
    […]

    Since the class has a user-declared copy assignment operator, neither of the implicit ones will be generated by the compiler.

    std::is_copy_assignable and std::is_move_assignable are described in table 49 as having the same value as, respectively is_assignable<T&,T const&>::value and is_assignable<T&,T&&>::value. That table tells us that is_assignable<T,U>::value is true when:

    The expression declval<T>() = declval<U>() is well-formed when treated
    as an unevaluated operand (Clause 5). Access checking is performed as
    if in a context unrelated to T and U. Only the validity of the
    immediate context of the assignment expression is considered.

    Since both declval<T&>() = declval<T const&>() and declval<T&>() = declval<T&&>() are well-formed for that class, it still counts as copy assignable and move assignable.

    As I mentioned in the comments, what’s curious about all this is that, in the presence of a move constructor, that operator= will correctly perform moves, but technically not count as a move assignment operator. It’s even stranger if the class has no copy constructor: it will have a copy assignment operator that doesn’t do copies, but only moves.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from
Generally this question comes from Eclipse suggesting to add a serial version UID on
This question has been puzzling me for a long time now. I come from
I come from Windows .Net forms development. This is a pretty basic/fundamental question. I'm
This may be a bit of daft question, but I don't come from an
Okay, this question comes through a friend so it might be lost in translation...
( Late edit: This question will hopefully be obsolete when Java 7 comes, because
Here's the question first: Is this possible? I'm taking my inspiration from Joe Wrobel's
This is a pretty generic question, but I come from a few years with
I've seen this question come up in a few places, and not seen any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.