问题
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 Symbolwarning is set toFalse, all others have the default valueOutput warningsis set toAs errors
The result:
- The
Platform Symbolwarning is muted (as expected) - The
Duplicate constructorwarning 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