[fpc-devel] Minor debate with ISO standard on case blocks

J. Gareth Moreton gareth at moreton-family.com
Tue Jul 30 00:47:52 CEST 2019


Hi everyone,

So there's been an issue raised 
<https://bugs.freepascal.org/view.php?id=35905> in regards to ISO 
compliance with case blocks (when under $mode iso).  Currently, a 
compiler error is raised if a case block does not have exhaustive 
coverage for the input type (it's a warning on other modes).

According to ISO7185 <http://pascal-central.com/docs/iso7185.pdf>, page 
55, section 6.8.3.5:

"On execution of the case-statement the case-index shall be evaluated. 
That value shall then specify execution of the statement of the 
case-list-element closest-containing thecase-constant denoting that 
value. One of the case-constants shall be equal to the value of the 
case-index upon entry to the case-statement; otherwise, it shall be an 
error."

Given it says "on execution", it implies this all occurs at run-time, 
especially as 'case-index' is usually a variable or otherwise 
non-deterministic at compile-time, hence the error should be a run-time 
error, not a compile-time error.  I think the issue is that FPC won't 
compile some well-known ISO Pascal code 
<https://bugs.freepascal.org/view.php?id=35859> because some of the case 
blocks don't exhaustively cover all inputs (which itself might be a sign 
of bad programming, but could be justified if said values are determined 
to be logically impossible, in which case the else blocks should contain 
assertions or internal errors).

Just interpreting the standard, I think that the error should be 
run-time, not compile-time (although definitely keep the warning).  
That's just my take on it though.  If it is to be changed, it should be 
simple enough by configuring the 'elselabel' field to point to an 
error-raising routine rather than 'endlabel' (which occurs if there's no 
else block).

Gareth aka. Kit



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190729/b2024df2/attachment.html>


More information about the fpc-devel mailing list