public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "carlosgalvezp at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107200] New: False positive -Wdangling-pointer? Date: Mon, 10 Oct 2022 13:33:01 +0000 [thread overview] Message-ID: <bug-107200-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107200 Bug ID: 107200 Summary: False positive -Wdangling-pointer? Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: carlosgalvezp at gmail dot com Target Milestone: --- Hi, The following code triggers a -Wdangling-pointer on GCC 12 and GCC 13: #include <iostream> #include <Eigen/Core> Eigen::Vector2d foo() { return {1.0, 2.0}; } int main() { auto x = 0.5 * foo(); std::cout << x(0) << ", " << x(1) << std::endl; } <source>: In function 'int main()': <source>:10:23: note: unnamed temporary defined here 10 | auto x = 0.5 * foo(); | ~~~^~ In member function 'const Eigen::internal::scalar_product_op<LhsScalar, RhsScalar>::result_type Eigen::internal::scalar_product_op<LhsScalar, RhsScalar>::operator()(const LhsScalar&, const RhsScalar&) const [with LhsScalar = double; RhsScalar = double]', inlined from 'Eigen::internal::binary_evaluator<Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>, Eigen::internal::IndexBased, Eigen::internal::IndexBased>::CoeffReturnType Eigen::internal::binary_evaluator<Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>, Eigen::internal::IndexBased, Eigen::internal::IndexBased>::coeff(Eigen::Index) const [with BinaryOp = Eigen::internal::scalar_product_op<double, double>; Lhs = const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 2, 1> >; Rhs = const Eigen::Matrix<double, 2, 1>]' at /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/CoreEvaluators.h:719:21, inlined from 'Eigen::DenseCoeffsBase<Derived, 0>::CoeffReturnType Eigen::DenseCoeffsBase<Derived, 0>::coeff(Eigen::Index) const [with Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 2, 1> >, const Eigen::Matrix<double, 2, 1> >]' at /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/DenseCoeffsBase.h:144:59, inlined from 'Eigen::DenseCoeffsBase<Derived, 0>::CoeffReturnType Eigen::DenseCoeffsBase<Derived, 0>::operator()(Eigen::Index) const [with Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 2, 1> >, const Eigen::Matrix<double, 2, 1> >]' at /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/DenseCoeffsBase.h:181:19, inlined from 'int main()' at <source>:11:37: /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/functors/BinaryFunctors.h:86:128: warning: using a dangling pointer to an unnamed temporary [-Wdangling-pointer=] 86 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; } | Reproducible on Godbolt: https://godbolt.org/z/7475f7WvK The warning goes away with this change: - auto x = 0.5 * foo(); + Eigen::Vector2d x = 0.5 * foo(); What could be the reason for this behavior? Thanks!
next reply other threads:[~2022-10-10 13:33 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-10 13:33 carlosgalvezp at gmail dot com [this message] 2022-10-10 15:20 ` [Bug c++/107200] " pinskia at gcc dot gnu.org 2022-10-10 19:10 ` [Bug tree-optimization/107200] " carlosgalvezp at gmail dot com 2022-10-10 19:38 ` remi.galanalfonso at gmail dot com 2022-10-11 6:07 ` carlosgalvezp at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107200-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).