Modify

Ticket #6396 (closed Bugs: fixed)

Opened 2 years ago

Last modified 2 years ago

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:

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

Attachments

Change History

comment:1 Changed 2 years ago by danivy.gmail@…

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 2 years ago by igaztanaga

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

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.