https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115135
--- Comment #4 from Carlos Alberto Lopez Perez <clopez at igalia dot com> --- FYI: Another way to workaround the issue and make the test pass is to tell GCC to not in-line the function doTest(). --- a/test.cpp 2024-05-17 03:15:07.275473492 +0000 +++ b/test.cpp 2024-05-20 13:18:51.334943200 +0000 @@ -75,7 +75,7 @@ class mTest; -int doTest(mTest& mObj, std::variant<std::unique_ptr<aTest>, std::unique_ptr<bTest>>&& dVar, std::shared_ptr<aTest> aPtr, bTest bObj) +int __attribute__ ((noinline)) doTest(mTest& mObj, std::variant<std::unique_ptr<aTest>, std::unique_ptr<bTest>>&& dVar, std::shared_ptr<aTest> aPtr, bTest bObj) { return switchOn(dVar, [&](std::unique_ptr<aTest>& ptr_a) -> int {