cereal icon indicating copy to clipboard operation
cereal copied to clipboard

GCC 13.2 build error: possible dangling reference to a temporary

Open kalibaer opened this issue 1 year ago • 2 comments

GCC 13.2 finds a possible dangling reference in include/cereal/details/polymorphic_impl.hpp line 204, 218, 231:

//.... error: possibly dangling reference to a temporary [-Werror=dangling-reference]
        auto const &mapping = lookup( baseInfo, typeid(Derived), [&](){ UNREGISTERED_POLYMORPHIC_CAST_EXCEPTION(save) } );
                    ^~~~~~~

kalibaer avatar Jan 10 '24 07:01 kalibaer

I also ran into this issue.

After some investigation this now looks it might be a compiler bug i.e. a false positive. The return time of the lookup function is std::vector<PolymorphicCaster const *> const & and the value is a reference to a vector stored in the map StaticObject<PolymorphicCasters>::getInstance().map which is not temporary.

There are a couple of other projects that reported similar compiler regressions on GCC 13, for example 107532.

marcosbento avatar Mar 26 '24 14:03 marcosbento

After updating from GCC 13.2 to 14.1, the false-positive warning is indeed gone.

This issue can probably be closed as this confirms that this is a compiler regression?

jgreitemann avatar Jun 27 '24 13:06 jgreitemann