boostorg / boostorg/test

Incorrect use of rvalue references and std::forward

Open
#315 0 comments 0 reactions 1 assignee Claimed by @raffienficiaud View on GitHub
Dominant language
C++
Stars
213
Forks
149
Avg merge
18h 17m
Merged PRs (30d)
2

Description

See: https://github.com/boostorg/test/blob/11a8d379b473ebe67dcc7792b6411ba312f60398/include/boost/test/data/monomorphic/grid.hpp#L96

Which boils down to

```cpp
template
class grid {
//! Constructor
grid( DataSet1&& ds1, DataSet2&& ds2 )
: m_ds1( std::forward( ds1 ) )
, m_ds2( std::forward( ds2 ) )
{}
};
```

Here `DataSet1` and `DataSet2`, while template parameters to the class, are not template parameters to the function.

As a result, this formulation of the constructor *always* takes these two parameters as rvalue-reference.

This can be corrected in 3 ways

1. Take both parameters by value
2. Make the constructor a template function
3. Make additional constructors that represent the cross-product of const& and && for each parameter. In this case, resulting in 4 functions.

I see that this same mistake is done in more than one place, it's not only grid.hpp where it happens.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.