public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107598] New: implicitly-defined copy/move assignment op not constexpr
@ 2022-11-09 19:26 mpolacek at gcc dot gnu.org
  2022-11-16 13:27 ` [Bug c++/107598] " jason at gcc dot gnu.org
  2022-11-16 14:09 ` mpolacek at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-11-09 19:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107598

            Bug ID: 107598
           Summary: implicitly-defined copy/move assignment op not
                    constexpr
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

The following test is rejected with:

bug1.C: In function ‘constexpr void g()’:
bug1.C:11:7: error: call to non-‘constexpr’ function ‘S& S::operator=(const
S&)’
   11 |   b = a;
      |       ^
bug1.C:5:4: note: ‘S& S::operator=(const S&)’ is not usable as a ‘constexpr’
function because:
    5 | S& S::operator=(const S&) = default;
      |    ^

...because what?

I think it should be accepted, at least in C++23, because
[class.copy.assign]/10:
"A copy/move assignment operator for a class X that is defaulted and not
defined as deleted is implicitly defined when it is odr-used ([basic.def.odr])
(e.g., when it is selected by overload resolution to assign to an object of its
class type), when it is needed for constant evaluation ([expr.const]), or when
it is explicitly defaulted after its first declaration.
The implicitly-defined copy/move assignment operator is constexpr."

Here it is explicitly defaulted after its first declaration.


struct S {
  constexpr S() {}
  S& operator=(const S&);
};
S& S::operator=(const S&) = default;

constexpr void
g ()
{
  S a, b;
  b = a;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/107598] implicitly-defined copy/move assignment op not constexpr
  2022-11-09 19:26 [Bug c++/107598] New: implicitly-defined copy/move assignment op not constexpr mpolacek at gcc dot gnu.org
@ 2022-11-16 13:27 ` jason at gcc dot gnu.org
  2022-11-16 14:09 ` mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jason at gcc dot gnu.org @ 2022-11-16 13:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107598

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> ---
It's not constexpr because it wasn't declared to be constexpr (or defaulted) in
the class body, and "If any declaration of a function or function template has
a constexpr or consteval specifier, then all its declarations shall contain the
same specifier."  The wording (and the error) could use some clarification.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/107598] implicitly-defined copy/move assignment op not constexpr
  2022-11-09 19:26 [Bug c++/107598] New: implicitly-defined copy/move assignment op not constexpr mpolacek at gcc dot gnu.org
  2022-11-16 13:27 ` [Bug c++/107598] " jason at gcc dot gnu.org
@ 2022-11-16 14:09 ` mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-11-16 14:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107598

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|rejects-valid               |
   Last reconfirmed|                            |2022-11-16
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Ah, thanks.  Then it's a diagnostic-only PR, we should still explain what the
problem is.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-16 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 19:26 [Bug c++/107598] New: implicitly-defined copy/move assignment op not constexpr mpolacek at gcc dot gnu.org
2022-11-16 13:27 ` [Bug c++/107598] " jason at gcc dot gnu.org
2022-11-16 14:09 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).