public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107200] New: False positive -Wdangling-pointer?
@ 2022-10-10 13:33 carlosgalvezp at gmail dot com
  2022-10-10 15:20 ` [Bug c++/107200] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: carlosgalvezp at gmail dot com @ 2022-10-10 13:33 UTC (permalink / raw)
  To: gcc-bugs

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!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-11  6:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 13:33 [Bug c++/107200] New: False positive -Wdangling-pointer? carlosgalvezp at gmail dot com
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

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).