public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107202] New: inheriting assignment operators from CRTP-base
@ 2022-10-10 19:32 h2+bugs at fsfe dot org
  0 siblings, 0 replies; only message in thread
From: h2+bugs at fsfe dot org @ 2022-10-10 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107202
           Summary: inheriting assignment operators from CRTP-base
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: h2+bugs at fsfe dot org
  Target Milestone: ---

I stumbled over the following:


```cpp
#define OPTION 0 // or 1-4

template <typename Derived>
struct Base
{
    Base() = default;
    Base(Base const &) = default;
    Base(Base &&) = default;
    //Base & operator=(Base const &) = delete;
    //Base & operator=(Base &&) = delete;

#if OPTION == 1
    Derived const & operator=(Derived &)
    {
        return static_cast<Derived &>(*this);
    }
#elif OPTION == 2
    Derived const & operator=(Derived &) const
    {
        return static_cast<Derived &>(*this);
    }
#elif OPTION == 3
    Derived const & operator=(Derived const &)
    {
        return static_cast<Derived &>(*this);
    }
#elif OPTION == 4
    Derived const & operator=(Derived const &) const
    {
        return static_cast<Derived &>(*this);
    }
#endif
};

struct D : Base<D>
{
    D() = default;
    D(D const &) = default;
    D(D &&) = default;
    //D & operator=(D const &) = delete;
    //D & operator=(D &&) = delete;

    using Base<D>::operator=;
};

int main()
{
    D d1;
    D d2;
    d1 = d2;
}
```


OPTION == 0 → no valid overload (expected!)
OPTION == 1 → well-formed
OPTION == 2 → ambiguous overload
OPTION == 3 → no valid overload
OPTION == 4 → no valid overload

Clang behaves the same as GCC. MSVC never sees any valid overloads.

My assumption was that implicit assignment operators are inhibited in all cases
(this is also shown by OPTION == 0), but that any of the inherited operators
should be valid. Should the implicit deletion of the assignment-operator in D
prevent inheriting the user-defined assignment operators from Base, why does
this affect some of them and not others?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-10 19:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 19:32 [Bug c++/107202] New: inheriting assignment operators from CRTP-base h2+bugs at fsfe dot 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).