Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I temporarily disable the "return value might be undefined" warning?

I want to disable a specific warning (W1035) in my code, since I think that the compiler is wrong about this warning:

function TfrmNagScreen.Run: TOption;
begin
  if ShowModal = mrOk then
    Result := TOption(rdgAction.EditValue)
  else
    Abort
end;

There is no way the result could be undefined, since Abort throws EAbort.

I tried:

  • {$WARN 1035 Off}: Apparently this only works for some specific errors (see Documentation)
  • {$W-1035}: Does nothing at all

I know I can switch off the warning globally in the project options, or using {$WARNINGS OFF}, but that is not what is intended here.

Edit: I have QC'ed this now as #89744.

like image 677
Jens Mühlenhoff Avatar asked Nov 17 '10 12:11

Jens Mühlenhoff


2 Answers

you can't disable this warning globally, but you can use the {$WARN NO_RETVAL OFF} to disable locally the warning.

{$WARN NO_RETVAL OFF}
function TfrmNagScreen.Run: TOption;
begin
  if ShowModal = mrOk then
    Result := TOption(rdgAction.EditValue)
  else
    Abort
end;
{$WARN NO_RETVAL ON}
like image 89
RRUZ Avatar answered Oct 06 '22 01:10

RRUZ


I don't have a Delphi compiler available at the moment, but rearranging the code to remove the if..else might make the warning go away:

function TfrmNagScreen.Run: TOption;
begin
  if ShowModal <> mrOk then
    Abort;

  Result := TOption(rdgAction.EditValue);
end;

See also How to disable a warning in Delphi about “return value … might be undefined”?.

like image 34
WileCau Avatar answered Oct 06 '22 00:10

WileCau