Hopefully the problem is obvious from the question :) If not, consider the following code:
template <typename Ty>
class test
{
public:
test(std::string &v) : val(v) {}
template <typename... Args>
test(Args&&... args) : val(std::forward<Args>(args)...) {}
Ty val;
};
int main(void)
{
std::cout << std::is_assignable<test<std::string>, std::string>::value << std::endl;
std::cout << std::is_assignable<test<std::string>, std::vector<int>>::value << std::endl;
}
The output is true in both cases, tested using Visual Studio 2013 update 3 as well as ideone. This just seems wrong to me on many different levels. For one, attempting to construct/assign std::vector<int>
to an instance of the type test<std::string>
will not compile (obviously). I can live with this as the compiler is likely just checking types and whether or not an acceptable function exists (and not whether or not said function compiles).
What bugs me the most is that constructors should have no effect on assignment. This seems to be true (at least in GCC) when removing the variadic constructor. The output is then false in both cases. On Visual Studio, the output is still true for the first line of output; I'll file a bug on that tomorrow.
Anyway, is this correct behavior? It seems quite counter-intuitive.