From 4fd642abb4dbe0a79958ff47f7b24a2bc6932c98 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 29 Jan 2020 18:50:45 -0600 Subject: [PATCH] Add lint check for return with no value in a non-void function. This is disallowed in C99 and later. --- Parser.pas | 7 ++++++- Scanner.pas | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Parser.pas b/Parser.pas index 03abacb..44a7544 100644 --- a/Parser.pas +++ b/Parser.pas @@ -763,7 +763,12 @@ var end; otherwise: ; end; {case} - end; {if} + end {if} + else begin + if (fType^.kind <> scalarType) or (fType^.baseType <> cgVoid) then + if (lint & lintC99Syntax) <> 0 then + Error(152); + end; {else} Gen1(pc_ujp, returnLabel); {branch to the exit point} Match(semicolonch, 22); {insist on a closing ';'} end; {ReturnStatement} diff --git a/Scanner.pas b/Scanner.pas index 9a8c48e..fae40d2 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -182,7 +182,7 @@ const {----} defaultName = '13:ORCACDefs:Defaults.h'; {default include file name} maxErr = 10; {max errors on one line} - maxLint = 151; {maximum lint error code} + maxLint = 152; {maximum lint error code} type errorType = record {record of a single error} @@ -676,6 +676,7 @@ if list or (numErr <> 0) then begin 149: msg := @'invalid universal character name for use in an identifier'; 150: msg := @'designated initializers are not supported by ORCA/C'; 151: msg := @'lint: type specifier missing'; + 152: msg := @'lint: return with no value in non-void function'; otherwise: Error(57); end; {case} writeln(msg^); @@ -3636,7 +3637,7 @@ lintIsError := true; {lint messages are considered errors} {error codes for lint messages} {if changed, also change maxLint} -lintErrors := [51,104,105,110,124,125,128,129,130,147,151]; +lintErrors := [51,104,105,110,124,125,128,129,130,147,151,152]; new(mp); {__LINE__} mp^.name := @'__LINE__';