The return type is , but is not used to allow congestion. It is important not to confuse the terms. In principle, a type includes arguments and a return value, but when overload is resolved, the return type is not considered. The type of function or function pointer is a contract between the caller and the called party, and they must fully agree with the conditions.
From a practical point of view, think about what will happen if what you offer is allowed. Imagine a calling agreement in which the caller reserves the space and passes a function to a pointer to that space, then the function will build the return object in this place (this is actually a very ordinary agreement). Think now that you have been allowed to complete your proposed throw and the following use case
static_assert(sizeof(T1)<sizeof(T2)); T2 f(); T1 (*p)() = &f; p();
Now that the compiler processes p() , it reserves a place somewhere and sets the type of function that it should reserve sizeof(T1) . It then calls a function that ends with a call to f , which writes sizeof(T2) bytes to the location, causing an overflow.
Even if the sizes match, the code will be problematic. Consider T1==int and T2==float in the platform, where sizeof(int)==sizeof(float) . Although the above code will not cause a buffer overflow, the bitpatter stored in the return type location will have a float value, not an int value.
source share