|
@@ -688,11 +688,8 @@ implementation
|
|
|
if assigned(elseblock) then
|
|
|
typecheckpass(elseblock);
|
|
|
|
|
|
- if not codegenerror and
|
|
|
- is_ordinal(left.resultdef) then
|
|
|
- checkordinalcoverage;
|
|
|
-
|
|
|
resultdef:=voidtype;
|
|
|
+ result:=simplify(false);
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -786,6 +783,22 @@ implementation
|
|
|
temp_cleanup:=nil;
|
|
|
expectloc:=LOC_VOID;
|
|
|
|
|
|
+ { only do in pass_1, so that simplify can run first and
|
|
|
+ 1) possibly simplify the case node without triggering a warning
|
|
|
+ 2) possibly give a compile-time error if not all cases are handled
|
|
|
+ in ISO/Extended Pascal mode }
|
|
|
+ if is_ordinal(left.resultdef) then
|
|
|
+ checkordinalcoverage;
|
|
|
+
|
|
|
+ { ideally this would be in simplify, but then checkordinalcoverage can
|
|
|
+ false positives about case statements not handling all cases }
|
|
|
+ if assigned(elseblock) and
|
|
|
+ has_no_code(elseblock) then
|
|
|
+ begin
|
|
|
+ elseblock.free;
|
|
|
+ elseblock:=nil;
|
|
|
+ end;
|
|
|
+
|
|
|
{ evalutes the case expression }
|
|
|
firstpass(left);
|
|
|
set_varstate(left,vs_read,[vsf_must_be_valid]);
|
|
@@ -942,14 +955,14 @@ implementation
|
|
|
if assigned(elseblock) then
|
|
|
result:=elseblock.getcopy
|
|
|
else
|
|
|
- { no else block, so there is no code to execute at all }
|
|
|
- result:=cnothingnode.create;
|
|
|
- end;
|
|
|
- if assigned(elseblock) and
|
|
|
- has_no_code(elseblock) then
|
|
|
- begin
|
|
|
- elseblock.free;
|
|
|
- elseblock:=nil;
|
|
|
+ begin
|
|
|
+ if ([m_iso,m_extpas]*current_settings.modeswitches)<>[] then
|
|
|
+ cgmessage1(cg_e_case_missing_value,tostr(tordconstnode(left).value))
|
|
|
+ else
|
|
|
+ cgmessage(cg_w_case_incomplete);
|
|
|
+ { no else block, so there is no code to execute at all }
|
|
|
+ result:=cnothingnode.create;
|
|
|
+ end;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
@@ -1219,16 +1232,13 @@ implementation
|
|
|
(labelcoverage<typcount) then
|
|
|
begin
|
|
|
{ labels for some values of the operand are missing, and no else block is present }
|
|
|
- if not(m_iso in current_settings.modeswitches) then
|
|
|
+ cgmessage(cg_w_case_incomplete);
|
|
|
+ { in Standard/Extended Pascal, this is a dynamic violation error if it actually happens }
|
|
|
+ if ([m_extpas,m_iso]*current_settings.modeswitches)<>[] then
|
|
|
begin
|
|
|
- cgmessage(cg_w_case_incomplete);
|
|
|
- { in Extended Pascal, this is a dynamic violation error if it actually happens }
|
|
|
- if (m_extpas in current_settings.modeswitches) then
|
|
|
- elseblock:=ccallnode.createintern('fpc_rangeerror',nil);
|
|
|
- end
|
|
|
- else
|
|
|
- { this is an error in ISO Pascal }
|
|
|
- message(cg_e_case_incomplete);
|
|
|
+ elseblock:=ccallnode.createintern('fpc_rangeerror',nil);
|
|
|
+ typecheckpass(elseblock);
|
|
|
+ end;
|
|
|
end
|
|
|
end
|
|
|
else if labelcoverage=typcount then
|