[Issue 13986] New: auto return for some recursive functions
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Thu Jan 15 09:57:55 PST 2015
    
    
  
https://issues.dlang.org/show_bug.cgi?id=13986
          Issue ID: 13986
           Summary: auto return for some recursive functions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc
According to Wikipedia:
http://en.wikipedia.org/wiki/C%2B%2B14#Function_return_type_deduction
C++14 is able to compile code like this:
auto correct(int i) {
    if (i == 1)
        return i;
    else
        return correct(i - 1) + i;
}
But not like this:
auto correct(int i) {
    if (i != 1)
        return correct(i - 1) + i;
    else
        return i;
}
D isn't able to compile both. Is it possible and a good idea to allow the first
function in D too?
The D spec says:
"If multiple return expressions are used in the function's implementation, then
they must all deduce the same type."
--
    
    
More information about the Digitalmars-d-bugs
mailing list