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

            Bug ID: 118383
           Summary: Constexpr default copy-assign operator of derived
                    class with virtual base seems should not be allowed
                    before C++23
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rush102333 at gmail dot com
  Target Milestone: ---

Consider the following code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

struct base { };
struct derived : virtual base {
    constexpr derived& operator=(derived const&) = default;
};

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://godbolt.org/z/evns8zEqq

It appears that the default 'operator=' here inside a class with a virtual base
class is not permitted to be declared as constexpr function until
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html#onwards-to-constexpr-classes,
 which targets for C++23. That means the code above should not be accepted
before that.


https://timsong-cpp.github.io/cppwp/n4861/dcl.fct.def.default#3.sentence-1
(C++20):

An explicitly-defaulted function that is not defined as deleted may be declared
constexpr or consteval only if it is constexpr-compatible ([special]).


See discussion on LLVM bug tracker:
https://github.com/llvm/llvm-project/issues/97266

Reply via email to