This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/12367] Incorrect code generation for meta/expression templates


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12367


ehrhardt at mathematik dot uni-ulm dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


------- Additional Comments From ehrhardt at mathematik dot uni-ulm dot de  2003-09-24 09:22 -------
I believe the code to be invalid. Can someone confirm this please?

Explanation:

We have in function prod:

template<...>
inline XprMatrix<...>
prod(const XprMatrix<...>& lhs, const Matrix<...>& rhs) {
  typedef XprMMProduct<...> expr_type;
  return XprMatrix<expr_type, ...> ( expr_type (...) );
}

So this constructs a temporary object of type epxr_type (actually
XprMMProduct<...>) and uses this temporary object to construct
another temporary object of type XprMatrix. The second temporary is then
returned by value. Now XprMatrix looks like this:

template<class E, unsigned Rows, unsigned Cols>
struct XprMatrix
{
  explicit XprMatrix(const E& e) : m_expr(e) { }
  [ ... ]
  const E& restrict  m_expr;
};

This means that m_expr is a direct reference to the temprory of type
XprMMProduct<...> created in function prod. However, the life time
of that temporary ends at exit of function prod. Thus prod returns
an object containing a reference to a tempory object that is dead after
prod returns. This invokes undefined behaviour.

     regards   Christian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]