### Control reaches end of non-void function

Hi forum,

I am running into an odd issue. G++ tells me a warning, `warning: control reaches end of non-void function [-Wreturn-type]`.
Any thoughts? My code is below, and it seems to me that it will always return something...

 ``123456789101112131415161718192021222324252627`` `````` bool Date::inRangeDay(int yy, int mm, int dd) const { if (13 > mm || 0 < mm) { if (mm == 2) { //leap year rules if (yy % 4 == 0) { if (yy % 100 == 0 && yy % 400 == 0) { return (1 <= dd && 29 >= dd) ? true : false; } else { return (1 <= dd && 29 >= dd) ? true : false; } } else { return (1 <= dd && 28 >= dd) ? true : false; } } else if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) { return (1 <= dd && 31 >= dd) ? true : false; } else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) { return (1 <= dd && 30 >= dd) ? true : false; } } else { return false; } }``````
You essentially have
 ``123456`` ``````IF A IF B THEN return ELSE IF C THEN return ELSE IF D THEN return ELSE ???? ELSE return``````

We do see that B, C or D will be true for all values for which A is true. The compiler does not calculate that and warns about the "impossible" path.

Consider
 ``123`` ``````if (mm == 2) else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) else``````

The (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) is true on the else, is it not?
Hi

The if statement on line 3 has no `else`, even though this might logically never happen, the compiler sees it as a possible path.

But your code is too complex IMO. Consider having a IsLeapYear function - a one liner; and use a vector for the months and the number of days they have - the subscript is the month number.

Good Luck !!
keskiverto, what if month is an invalid `14`?

I see what youre saying about the pseudocode, but I think I need to do it like this:

 ``1234`` ``````if (mm == 2) else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) else if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) else``````

Does it sound feasible to you?

TheIdeasMan, we have not learned vectors yet, thank you for your input.
Edit

Got it:

 ``123456789101112131415161718192021222324252627`` `````` bool Date::inRangeDay(int yy, int mm, int dd) const { if (13 > mm || 0 < mm) { if (mm == 2) { //leap year rules if (yy % 4 == 0) { if (yy % 100 == 0 && yy % 400 == 0) { return (1 <= dd && 29 >= dd) ? true : false; } else { return (1 <= dd && 29 >= dd) ? true : false; } } else { return (1 <= dd && 28 >= dd) ? true : false; } } else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) { return (1 <= dd && 30 >= dd) ? true : false; } else { return (1 <= dd && 31 >= dd) ? true : false; } } else { return false; } }``````
 TheIdeasMan, we have not learned vectors yet, thank you for your input.

Well you could use an ordinary array then :+)

It beats me that people know about classes, but not basic STL containers :+)