[eigen] Assigning a dynamic matrix to a fixed size matrix const reference causes invalid read |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: "eigen@xxxxxxxxxxxxxxxxxxx" <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: [eigen] Assigning a dynamic matrix to a fixed size matrix const reference causes invalid read*From*: Robert Johannes Langenberg <robert.langenberg@xxxxxxx>*Date*: Wed, 20 Nov 2013 17:10:28 +0000*Accept-language*: de-DE, en-US*Cc*: Walter Lampl <Walter.Lampl@xxxxxxx>*Thread-index*: AQHO5hNpR5bz9PYrf0et6gWYN3A4Eg==*Thread-topic*: Assigning a dynamic matrix to a fixed size matrix const reference causes invalid read

Hi, Valgrind shows we've been getting invalid reads when assigning a dynamically sized matrix to a const reference of a fixed size matrix. The content of the fixed size matrix is nothing useful after the assignment. How does gcc not detect I'm trying to assign a different type to a reference? Debugging showed the copy constructor is called, while from my understanding it should just fail (or just assign the reference pointer, but not call a constructor). Non-const references fail as expected. Assigning pointers fails as expected as well. Here a piece of code that reproduces the behavior: #include <Eigen/Dense> #include <iostream> int main() { Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> dynMatr(2,2); dynMatr(0,0)=1; dynMatr(0,1)=2; dynMatr(1,0)=3; dynMatr(1,1)=4; //Should fail to compile because of type mismatch! const Eigen::Matrix<double,5,5,0,5,5>& refFixed=dynMatr; std::cout << "Original:" << dynMatr(1,1) << std::endl; std::cout << "Matrix<5x5> reference type: " << refFixed(1,1) << std::endl; return 0; } The output is: play% g++ -DNDEBUG basictest.cxx play% ../a.out Original:4 Matrix<5x5> reference type: 0 Thanks and best regards, Robert |

**Attachment:
signature.asc**

**Follow-Ups**:**Re: [eigen] Assigning a dynamic matrix to a fixed size matrix const reference causes invalid read***From:*Christoph Hertzberg

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Fix for ARM __builtin_prefetch fails** - Next by Date:
**Re: [eigen] Assigning a dynamic matrix to a fixed size matrix const reference causes invalid read** - Previous by thread:
**Re: [eigen] Fix for ARM __builtin_prefetch fails** - Next by thread:
**Re: [eigen] Assigning a dynamic matrix to a fixed size matrix const reference causes invalid read**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |