This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12367] Incorrect code generation for meta/expression templates
- From: "ehrhardt at mathematik dot uni-ulm dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Sep 2003 09:22:55 -0000
- Subject: [Bug c++/12367] Incorrect code generation for meta/expression templates
- References: <20030922150454.12367.opetzold@wit.regiocom.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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