How to treat warnings as errors in Delphi 10.2 while setting some warnings to False

十年热恋 提交于 2020-05-15 08:02:27

问题


In Delphi 10.2 there is this option to treat warnings as errors (Project options -> Delphi Compiler -> Hints and Warnings -> Output warnings). The optiona are True, False and as errors. When set to as errors the compiler will treat every warning as an error, making the build fail. For me, this is essential as I want my build server to fail on any warning (I am using a Microsoft Azure DevOps build pipeline).

The problem is that when I set any of the listed warnings to a non-default value (for instance, when I set Platform Symbol to False to ignore any platform symbol warnings), the as errors settings does not work anymore. All warnings are then outputted as normal warnings, instead of errors (except for the Platform Symbol warning in this example of course).

I know that I can use the $WARN <identifier> OFF directive to disable a specific warning, and that does respect the as errors setting, but this directive has local scope, so that means I have to add it to every unit that has this warning. I rather use a solution that has global scope and works for the whole project.

My question:
How can I let the compiler treat warnings as errors and disable some warnings globally?

Update 1

The warning that is still reported as a warning when Output warnings is set to True, while some warnings are set to False is the W1029 Duplicate constructor ... with identical parameters will be inacessible in C++. In my case, the code uses platform specific symbols so I set the Platform Symbols warning to False, since I am targetting Windows only.

Update 2

To clarify my situation: My code has two warnings:

  • Platform symbol warning
  • Duplicate constructor warning

I use the following settings:

  • Platform Symbol warning is set to False, all others have the default value
  • Output warnings is set to As errors

The result:

  • The Platform Symbol warning is muted (as expected)
  • The Duplicate constructor warning is still output as a warning instead of as an error.

When I set Platform Symbol warning to True, the Platform Symbol warning does get treated as an error and stops compilation.

来源:https://stackoverflow.com/questions/61497184/how-to-treat-warnings-as-errors-in-delphi-10-2-while-setting-some-warnings-to-fa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!