Skip to content

molecular_dynamics_cells.cpp initializes reference from temporary #99

@LegalizeAdulthood

Description

@LegalizeAdulthood

In the following code:

        interaction_functor( hash_vector const& cells_begin , hash_vector const& cells_end , hash_vector pos_order ,
                            point_vector const&x , point_vector const& v , params const &p )
        : m_cells_begin( cells_begin ) , m_cells_end( cells_end ) , m_order( pos_order ) , m_x( x ) , m_v( v ) ,
        m_p( p ) { }

The member variable m_order, which is declared as:

        hash_vector const &m_order;

is initialized from the constructor function call argument hash_vector pos_order, which is a temporary, so that when the constructor exits, the member variable is holding a reference to junk. This results in the following line of code indexing an empty hash_vector and asserting under MSVC:

                        if( m_order[ ii ] == pos_hash ) continue;

I believe the correct fix is to change the type of the parameter to const hash_vector &. If I do this locally, then the assert doesn't fire. Pull request to follow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions