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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-06-06

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced to remove the library dependency:

// This is just a simple (incomplete) unique_ptr implementation that should
work with C++20/GCC >= 10.1.
// The details of this class don't matter. It also fails with std::unique_ptr
with GCC=12.1/trunk
template<class T>
class simple_pointer {
private:
    T *ptr{};
public:
    constexpr simple_pointer() noexcept = default;
    constexpr simple_pointer(T *p) noexcept : ptr{p} {}
    simple_pointer(const simple_pointer &) = delete;
    constexpr simple_pointer(simple_pointer &&p) noexcept : ptr{p.ptr} {}
    constexpr ~simple_pointer() noexcept { delete ptr; }

    void operator=(const simple_pointer &) = delete;
    constexpr simple_pointer &operator=(simple_pointer &&p) noexcept {
        delete ptr;
        ptr = p.ptr;
        p.ptr = nullptr;
        return *this;
    }

    constexpr T &operator*() const noexcept { return *ptr; }
    constexpr T *operator->() const noexcept { return ptr; }
};

template<class T>
constexpr simple_pointer<T> make_simple() {
    return simple_pointer<T>(new T());
}

// Just some random struct that has a vtable.
struct S {
    int x{42};

    // Removing this virtual...
    constexpr virtual ~S() noexcept = default;
};

// ... or this consteval makes it work again.
consteval int run() {
    auto p = make_simple<S>();
    return p->x;
}

int main() {
    return run();
}



105846.C: In function ‘int main()’:
105846.C:46:15:   in ‘constexpr’ expansion of ‘run()’
105846.C:43:1:   in ‘constexpr’ expansion of ‘(&
p)->simple_pointer<S>::~simple_pointer()’
105846.C:12:44: error: ‘virtual constexpr S::~S()’ used before its definition
   12 |     constexpr ~simple_pointer() noexcept { delete ptr; }
      |                                            ^~~~~~~~~~

Reply via email to