Search code examples
delphi-2007suppress-warnings

How do I get the command line Delphi-2007 compiler to ignore or suppress a particular warning


I am using Delphi 2007. I know how to get the IDE compiler to suppress/ignore particular warnings.

But how do I get the command line compiler to do this ?


Solution

  • You use the -W-[WARNING] option. The following example turns off W1036 ("Variable %s might not have been initialized"):

    dcc32 test.dpr -W-USE_BEFORE_DEF
    

    The only way I've found to find out the warning name to use is to create a simple console project in the IDE, add code that will produce the warning you want to identify, and then set the Project->Options-Compiler-Hints and Warnings to suppress that warning. Then build your project. Show the Messages window, go to the Output tab, Ctrl+A to Select all, Ctrl+C to copy.

    • Create a new console app.

      program Test1;
      
      {$APPTYPE CONSOLE}
      
      uses
        SysUtils;
      
      begin
        WriteLn('Test1');
        ReadLn;
      end.
      
    • Use Project->Options->Compiler`->Hints and Warnings, and turn off the warning(s) you want to suppress.

    • Build your test project.
    • In the Output tab of the Messages window, select all (Ctrl+A or using the context menu) and copy to the clipboard (Ctrl+C or via the context menu).
    • In a new Notepad window (or a new editor tab), paste in the contents of the clipboard. You'll find a long block of dcc32.exe command line similar (but probably much longer) than this (I've emphasized the relevant parts to notice):

    Build started 02/05/2016 2:48:48 PM.


    Project "E:\Code\Project1.dproj" (Make target(s)): Target CoreCompile: c:\rad studio\5.0\bin\dcc32.exe -DDEBUG;DEBUG -I"c:\rad studio\5.0\lib";"c:\rad studio\5.0\Imports";"C:\Users\Public\Documents\RAD Studio\5.0\Dcp";E:\Code\FastMM4;E:\madCollection\madBasic\BDS4;E:\madCollection\madDisAsm\BDS4;E:\madCollection\madExcept\BDS4;"E:\Code\Virtual Treeview\Source";E:\code\Indy10_5294\Lib\Core;E:\code\Indy10_5294\Lib\System;E:\code\Indy10_5294\Lib\Protocols; --SNIPPED ANOTHER DOZEN LINES-- --no-config -W-USE_BEFORE_DEF Project1.dpr

    Build succeeded. 0 Warning(s) 0 Error(s) Time Elapsed 00:00:00.12

    So as a result of all this, we've identified USE_BEFORE_DEF as the warning name for W1036 for use with the command line compiler, as well as illustrated exactly how to supply it to the compiler.

    You can, of course, disable more than one warning in order to identify them; I've just used one for simplicity, and snipped out a lot of the command-line output that is produced.