From Herb Sutter\'s GotW #6
Return-by-value should normally be const for non-builtin return types. ...
Note: Lakos (pg. 618) argues again
Here's a simple example involving function pointers:
const int f_const(int) { return 42; }
int f(int) { return 42; }
template <typename T>
void g(T(*)(T))
{
return;
}
int main()
{
g(&f_const); // doesn't work: function has type "const int (*)(int)"
g(&f); // works: function has type "int (*)(int)"
}
Note that Visual C++ 2010 incorrectly accepts both. Comeau 4.3.10 and g++ 4.1.2 correctly do not accept the g(&f_const)
call.