Opened 5 years ago

Closed 5 years ago

#6396 closed Bugs (fixed)

Implicit instanciation of boost::rv for non-cass types generates an error

Reported by: danivy.mail@… Owned by: igaztanaga
Milestone: To Be Determined Component: move
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:


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;

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.


#include <boost/move/move.hpp>

template <typename T>
class wrapper {

	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

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by…

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.

comment:2 Changed 5 years ago by igaztanaga

  • Resolution set to fixed
  • Status changed from new to closed

Avoided inheritance from T when type is not a class or union. Revision: 76509

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain igaztanaga.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.