From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 739833858439; Mon, 10 Oct 2022 13:33:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 739833858439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665408782; bh=DyUvmqHducBPqOogwIOtoXOEe5Ue0s9x18o+cBB6cHY=; h=From:To:Subject:Date:From; b=DYxwoD2gtZGUfq7ZjM2fz6wccFNlG+iMIcCta6+D2A2ay0aDF99F1UpDQDLaCHx7W oeKg4qir5Ffn1C3IWKNVV9fYDKcphZwv33Pq0LVsqyNU59NAMmJEbBjcjm13iW355p 6p7YrlfW3rOs26gEZXPU71Q41UQhQ6PqgksxerOA= From: "carlosgalvezp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107200] New: False positive -Wdangling-pointer? Date: Mon, 10 Oct 2022 13:33:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: carlosgalvezp at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107200 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,=20 The following code triggers a -Wdangling-pointer on GCC 12 and GCC 13: #include #include Eigen::Vector2d foo() {=20 return {1.0, 2.0}; } int main() { auto x =3D 0.5 * foo(); std::cout << x(0) << ", " << x(1) << std::endl; } : In function 'int main()': :10:23: note: unnamed temporary defined here 10 | auto x =3D 0.5 * foo(); | ~~~^~ In member function 'const Eigen::internal::scalar_product_op::result_type Eigen::internal::scalar_product_op::operator()(const LhsScalar&, const RhsScalar&) const [with LhsScalar =3D double; RhsScalar =3D double]', inlined from 'Eigen::internal::binary_evaluator, Eigen::internal::IndexBased, Eigen::internal::IndexBased>::CoeffReturnType Eigen::internal::binary_evaluator, Eigen::internal::IndexBased, Eigen::internal::IndexBased>::coeff(Eigen::Ind= ex) const [with BinaryOp =3D Eigen::internal::scalar_product_op= ; Lhs =3D const Eigen::CwiseNullaryOp, const Eigen::Matrix >; Rhs =3D const Eigen::Matrix]' at /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/CoreEvaluators.h:71= 9:21, inlined from 'Eigen::DenseCoeffsBase::CoeffReturnType Eigen::DenseCoeffsBase::coeff(Eigen::Index) const [with Derived= =3D Eigen::CwiseBinaryOp, co= nst Eigen::CwiseNullaryOp, const Eigen::Matrix >, const Eigen::Matrix >]' at /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/DenseCoeffsBase.h:1= 44:59, inlined from 'Eigen::DenseCoeffsBase::CoeffReturnType Eigen::DenseCoeffsBase::operator()(Eigen::Index) const [with Derived =3D Eigen::CwiseBinaryOp, const Eigen::CwiseNullaryOp, const Eigen::Matrix >, const Eigen::Matrix >]' at /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/DenseCoeffsBase.h:1= 81:19, inlined from 'int main()' at :11:37: /opt/compiler-explorer/libs/eigen/v3.3.9/Eigen/src/Core/functors/BinaryFunc= tors.h:86:128: warning: using a dangling pointer to an unnamed temporary [-Wdangling-point= er=3D] 86 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; } |=20=20=20=20=20 Reproducible on Godbolt: https://godbolt.org/z/7475f7WvK The warning goes away with this change: - auto x =3D 0.5 * foo(); + Eigen::Vector2d x =3D 0.5 * foo(); What could be the reason for this behavior? Thanks!=