News for hackers. Stuff that matters.
Re:The C++14 Standard: What You Need to Know by freditup on Wednesday September 17, 2014 @09:54AM (#8329921)
> For example, if a function has multiple return paths, they need to have the same type.

> ...

> [Code sample that returns -1 or record->id]

> Instead of using an integral type to identify the person in the record object, maybe I have a new GUID type. Making that change to the record object will cause a series of cascading changes in things like the return types of functions. But if my function uses automatic return type deduction, the compiler will silently make the change for me.

Yet when this happens, his example function can now return -1 or a GUID, so compilation should fail, no? Haven't worked with C++ in awhile so I might just be missing something on this, but seems like a contradiction to me.

Re:The C++14 Standard: What You Need to Know by pyrois on Wednesday September 17, 2014 @10:05AM (#8329981)
I'm not sure if implicit conversions are applied to type deductions. It could be that GUID has a constructor that takes in an integer, which would mean that if the function were declared with a return type of "GUID", returning -1 would be fine. I don't know if the same applies to functions with "auto" as the return type, but the example with the int and the double suggests not. So, this is a long-winded way of saying "yes, I think it's a bug".
Re:The C++14 Standard: What You Need to Know by ubercore on Wednesday September 17, 2014 @09:57AM (#8329936)
No, the return type can change as long as all return paths return the same value for the same function call. So you can't, in the same execution, return two different types, but two different executions can vary their return type as long as its consistent.
Re:The C++14 Standard: What You Need to Know by pyrois on Wednesday September 17, 2014 @10:12AM (#8330035)
The point is that -1 is not a GUID, though, so in the sample function, if record::id changes to a GUID, the find_id function is now trying to return -1 (an integer) and ii->id (a GUID).
Re:The C++14 Standard: What You Need to Know by ubercore on Wednesday September 17, 2014 @10:48AM (#8330240)
Right. Thanks for correcting me, I missed that.