https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107200
Rémi Galan Alfonso <remi.galanalfonso at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |remi.galanalfonso at gmail dot com --- Comment #3 from Rémi Galan Alfonso <remi.galanalfonso at gmail dot com> --- Hello, If I remember correctly, Eigen uses expression templates (and the names in the inline stack make it look like it). In that case your auto would not be Eigen::Vector2d (which you can see in your godbolt by adding e.g. "static_assert(std::is_same<decltype(x), Eigen::Vector2d>::value, "Not Eigen::Vector2d.");"), it would be a type that represents the expression "0.5 * Eigen::Vector2d{1.0, 2.0}", which probably contains a reference to the temporary Vector2d, which is destroyed at the end of the line, before the "x(0)" and "x(1)". And that would explain why you don't see the problem when you replace the auto with "Eigen::Vector2d", as in that case that causes the evaluation of the expression template while the temporary still exists. Moreover, if you enable "Execute the code" on godbolt and add the option "-fsanitize=address", it trigger the address sanitizer with auto and not Vector2d, with "ERROR: AddressSanitizer: stack-use-after-scope". (And bonus: when running the code without sanitizer in O3, what is printed is not the "expected" result, for example I get "0, 1.03725e-317" on godbolt, GCC optimized assuming the code doesn't use the dangling values) So I think the warning is correct, but you probably want to wait for confirmation from a GCC developer ;).