https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95950
Bug ID: 95950 Summary: Call to pseudo-destructor does not end the lifetime until C++20 Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kutdanila at yandex dot ru Target Milestone: --- #include <optional> int main() { std::optional<int> t = 2; using T = std::optional<int>; t.~T(); return t.has_value(); } g++ test.cpp -O1 -o test This code should not return 0 until C++20, see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0593r4.html and http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0593r4.html#c5-c-and-iso-c-2017-diffcpp17 In that case, std::optional<int> has a trivial destructor and should have no effect The regression started somewhere in the 9th version of gcc in any optimized builds (O1-O3, with O0 still ok) Yet, static_assert works fine #include <optional> int main() { constexpr std::optional<int> t = 2; using T = std::optional<int>; t.~T(); static_assert(t.has_value()); }