Opened 11 years ago
Closed 11 years ago
#6396 closed Bugs (fixed)
Implicit instanciation of boost::rv for non-cass types generates an error
| Reported by: | Owned by: | Ion Gaztañaga | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | move |
| Version: | Boost 1.48.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
boost::rv<T> unconditionally inherits from T. During overload-resolution, the compiler is allowed to instanciate parameter types even if not strictly necessary, which can lead to instanciation of rv for non-class types, causing an error.
For example:
#include <boost/move/move.hpp>
template <typename T>
struct vector {
void push_back(const T&) {}
void push_back(BOOST_RV_REF(T)) {}
};
int main()
{
vector<int> v;
v.push_back(123);
}
Fails on Sun 5.12 with:
"/usr/include/boost/move/move.hpp", line 231: Error: The base "boost::T" must be a previously defined class or struct. "main.cpp", line 12: Where: While specializing "boost::rv<int>". "main.cpp", line 12: Where: Specialized in non-template code.
And
#include <boost/move/move.hpp>
template <typename T>
class wrapper {
BOOST_COPYABLE_AND_MOVABLE_ALT(wrapper)
public:
wrapper(const T&) {}
wrapper(BOOST_RV_REF(T)) {}
wrapper(const wrapper&) {}
wrapper(BOOST_RV_REF(wrapper)) {}
};
int main()
{
wrapper<int> w1(123);
wrapper<int> w2(boost::move(w1));
}
fails on GCC 4.4.3 with:
/usr/include/boost/move/move.hpp: In instantiation of ‘boost::rv<int>’: main.cpp:17: instantiated from here /usr/include/boost/move/move.hpp:231: error: base type ‘int’ fails to be a struct or class type
Change History (2)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Avoided inheritance from T when type is not a class or union. Revision: 76509
Note:
See TracTickets
for help on using tickets.

The fix would be to specialize boost::rv for non-class types, avoiding inheritance. This specialization will never be used, but it will shush the compilers.