[Bug libstdc++/115846] std::optional<std::unique_ptr<int>> is constant expression even in C++20 mode
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jul 9 17:54:30 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115846
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I think the `intent` of std::optional is have it similar to something like
myoptional (not exactly but you should get the idea) below:
```
struct f
{
~f(){}
};
struct myoptional
{
f *t = nullptr;
constexpr ~myoptional() {reset(); }
constexpr void reset() { delete t; t = nullptr; }
constexpr myoptional &operator =(const f&&a) { reset(); t = new f(a); return
*this; }
};
static_assert([] {
myoptional opt;
opt.reset();
//opt = f{};
return true;
}());
```
If so then libstdc++ is still correct.
More information about the Gcc-bugs
mailing list