Prevent heap allocation in diagonal product
diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h
index 453f69b..6cbea6d 100644
--- a/Eigen/src/Core/DiagonalMatrix.h
+++ b/Eigen/src/Core/DiagonalMatrix.h
@@ -134,7 +134,7 @@
   typedef Matrix<Scalar_,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
   typedef DiagonalShape StorageKind;
   enum {
-    Flags = LvalueBit | NoPreferredStorageOrderBit
+    Flags = LvalueBit | NoPreferredStorageOrderBit | NestByRefBit
   };
 };
 }
diff --git a/test/diagonalmatrices.cpp b/test/diagonalmatrices.cpp
index 276bead..a88c3c1 100644
--- a/test/diagonalmatrices.cpp
+++ b/test/diagonalmatrices.cpp
@@ -7,6 +7,12 @@
 // Public License v. 2.0. If a copy of the MPL was not distributed
 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+
+// discard stack allocation as that too bypasses malloc
+#define EIGEN_STACK_ALLOCATION_LIMIT 0
+// heap allocation will raise an assert if enabled at runtime
+#define EIGEN_RUNTIME_NO_MALLOC
+
 #include "main.h"
 using namespace std;
 template<typename MatrixType> void diagonalmatrices(const MatrixType& m)
@@ -56,6 +62,7 @@
   Index i = internal::random<Index>(0, rows-1);
   Index j = internal::random<Index>(0, cols-1);
   
+  internal::set_is_malloc_allowed(false);
   VERIFY_IS_APPROX( ((ldm1 * m1)(i,j))  , ldm1.diagonal()(i) * m1(i,j) );
   VERIFY_IS_APPROX( ((ldm1 * (m1+m2))(i,j))  , ldm1.diagonal()(i) * (m1+m2)(i,j) );
   VERIFY_IS_APPROX( ((m1 * rdm1)(i,j))  , rdm1.diagonal()(j) * m1(i,j) );
@@ -65,6 +72,7 @@
   VERIFY_IS_APPROX( (((v1+v2).asDiagonal() * (m1+m2))(i,j))  , (v1+v2)(i) * (m1+m2)(i,j) );
   VERIFY_IS_APPROX( ((m1 * (rv1+rv2).asDiagonal())(i,j))  , (rv1+rv2)(j) * m1(i,j) );
   VERIFY_IS_APPROX( (((m1+m2) * (rv1+rv2).asDiagonal())(i,j))  , (rv1+rv2)(j) * (m1+m2)(i,j) );
+  internal::set_is_malloc_allowed(true);
   
   if(rows>1)
   {
@@ -84,7 +92,14 @@
   big.block(i,j,rows,cols) = m1;
   big.block(i,j,rows,cols) = big.block(i,j,rows,cols) * rv1.asDiagonal();
   VERIFY_IS_APPROX((big.block(i,j,rows,cols)) , m1 * rv1.asDiagonal() );
-  
+
+  // products do not allocate memory
+  MatrixType res(rows, cols);
+  internal::set_is_malloc_allowed(false);
+  res.noalias() = ldm1 * m;
+  res.noalias() = m * rdm1;
+  res.noalias() = ldm1 * m * rdm1;
+  internal::set_is_malloc_allowed(true);  
   
   // scalar multiple
   VERIFY_IS_APPROX(LeftDiagonalMatrix(ldm1*s1).diagonal(), ldm1.diagonal() * s1);