Consider the following small example:
template<typename T> void foo(T a) { ... }
struct Bar { ... };
Bar x;
foo(x);
My question: Are there any cases where foo(x) may be interpreted as foo(const Bar& x) (x passed by reference), or is it always interpreted as foo(Bar x) (x passed by value i.e. explicit copy of x)?
In my concrete application my code relies on the fact that a copy is created (x is used in another thread and the original x goes out of scope). But I am not sure if I can assume that. I am using GCC 4.6.1.
If deduced, it will always be passed by value. However, if you make the template arguments explicit, you can get it passed by reference: