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

            Bug ID: 91630
           Summary: std::any SFINAE breaks valid code since 9.1
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alabuzhev at hotmail dot com
  Target Milestone: ---

The following code compiles fine with 8.3, but not with 9.1 or later:

#include <any>

template<typename T>
class wrapper
{
public:
    wrapper() = default;

// Change to 0 to make it work
#if 1
    wrapper(const T& t)
    {
        // To make sure it's not instantiated
        static_assert(!sizeof(t));

        value = t;
    }
#endif

    wrapper(const wrapper& w)
    {
        // To make sure it's not instantiated
        static_assert(!sizeof(w));

        value = w.value;
    }

    auto& operator=(const T& t)
    {
        // To make sure it's not instantiated
        static_assert(!sizeof(t));

        value = t;
        return *this;
    }

    auto& operator=(const wrapper& w)
    {
        value = w.value;
        return *this;
    }

private:
    T value;
};

int main()
{
    wrapper<std::any> a, b;
    a = b;
}


See compiler explorer demo:
https://godbolt.org/z/q3o0TX

Reply via email to