Should unreachable code be considered an error?
Don
nospam at nospam.com
Wed Aug 31 01:56:52 PDT 2011
On 29.08.2011 15:29, Stewart Gordon wrote:
> On 25/08/2011 02:41, Michel Fortin wrote:
> <snip>
>> bool frontEquals(R, V)(R range, V value)
>> {
>> if (range.empty)
>> return false;
>> else
>> return range.front == value;
>> }
>>
>> This will work fine with most ranges, but if you encounter an infinite
>> range (with empty
>> defined as "enum empty = false") then the "return false" statement
>> becomes unreachable and
>> you'll get an error/warning? It doesn't make sense.
> <snip>
>
> The structure of a flowchart is not affected by the values of variables,
> or even constants, in it.
> _____________
> ( frontEquals )
> ¯¯¯¯¯¯|¯¯¯¯¯¯
> ______________ ______v______
> ( return false )<--- true ---< range.empty >
> ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯|¯¯¯¯¯¯
> false
> |
> ______________v______________
> ( return range.front == value )
> ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
> Replacing "range.empty" with "false" doesn't magically cause the true
> arrow to vanish.
>
> Stewart.
What if range.empty is simply the compile-time constant 'false'?
Isn't:
if (false) {...}
unreachable code?
If it doesn't create an error, what would?
More information about the Digitalmars-d
mailing list