Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a DCC32 option to treat a specific compiler warning as an error?

For command-line builds, I would like to treat warnings (for example "Constructing instance containing abstract method") as errors. I have not found a dcc32 command line option for this purpose in Delphi 2009. Is there a way, for example using dcc32.cfg, to do this?

like image 498
mjn Avatar asked Mar 13 '13 11:03

mjn


People also ask

How do I make GCC warnings as errors?

You can use the -Werror compiler flag to turn all or some warnings into errors. Show activity on this post. You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning. Unfortunately, in this case there isn't any specific option that covers that warning.

How do you treat warning errors?

TreatWarningsAsErrors. The TreatWarningsAsErrors option treats all warnings as errors. You can also use the TreatWarningsAsErrors to set only some warnings as errors. If you turn on TreatWarningsAsErrors, you can use WarningsNotAsErrors to list warnings that shouldn't be treated as errors.

Should I treat warnings as errors?

Yes, even once in a while you will encounter the occasional warning you'd be better off leaving as a warning or even disabling completely. Those should be the exception to the rule, though. Here's some practical advise: at the start of a new project, start treating all warnings as errors, by default.


1 Answers

Like this:

dcc32 -W^^CONSTRUCTING_ABSTRACT MyProject.dpr

For example, with this program:

program MyProject;

type
  TMyClass = class
    procedure X; virtual; abstract;
  end;

begin
  TMyClass.Create;
end.

And here's the output:

>dcc32 MyProject.dpr
Embarcadero Delphi for Win32 compiler version 24.0
Copyright (c) 1983,2012 Embarcadero Technologies, Inc.
Myproject.dpr(9) Warning: W1020 Constructing instance of 'TMyClass' containing abstract method 'TMyClass.X'
Myproject.dpr(12)
13 lines, 0.03 seconds, 21568 bytes code, 13256 bytes data.

>dcc32 -W^^CONSTRUCTING_ABSTRACT MyProject.dpr
Embarcadero Delphi for Win32 compiler version 24.0
Copyright (c) 1983,2012 Embarcadero Technologies, Inc.
Myproject.dpr(9) Error: E1020 Constructing instance of 'TMyClass' containing abstract method 'TMyClass.X'
Myproject.dpr(12)

If you want all warnings to be treated as errors then you do it like this:

dcc32 -W^^ MyProject.dpr

For further reading I refer you to Delphi XE2's hidden hints and warnings options.

like image 86
David Heffernan Avatar answered Oct 21 '22 10:10

David Heffernan