Forum > Third party

Generator for compiler warnings directive

(1/1)

gidesa:
Hello,
the FPC compiler has the $WARN directive to manage warnings, hints and notes.
Only a little group of these messages can be managed by name,  see  https://www.freepascal.org/docs-html/prog/progsu80.html.
All messages can be managed by number, see https://wiki.freepascal.org/Turn_warnings_and_hints_on_or_off.
Although is not so easy to extract message number.
An interesting, although undocumented, feature is that all warning/hint/note can be "promoted" to error, causing the compiler to stop. So one could have fine grained compiler checks on single units/functions.
I have wrote a simple Lazarus program that list all possible warnings, hints and notes, and generate corresponding directives for selected ones. See image.
The messages are read from FPC errore.msg file. You can found it in <fpc source directory>\compiler\msg   folder.
Attached the program source.
   

Thaddy:
Lazarus itself contains similar and better code and can be accessed through project options|compiler|messages.
Also the option to treat warnings - or hints, even notes - as errors IS documented. And the error codes can easily be accessed and found.
But thanks for your effort, I might use it under Geany, maybe as a plugin.
OTOH you can also copy out the revelant code from the Lazarus sourcecode.

gidesa:

--- Quote from: Thaddy on April 05, 2024, 04:08:26 pm ---Lazarus itself contains similar and better code and can be accessed through project options|compiler|messages.

--- End quote ---

No, the Lazarus options|compiler|messages page does NOT have the ERROR option for messages, only on/off. Doesn't have message type and number. And it's also valid for the entire project, not single unit/functions.
So, different scopes.


--- Quote ---Also the option to treat warnings - or hints, even notes - as errors IS documented. And the error codes can easily be accessed and found.
--- End quote ---

I don't have found any documentation on the fact that -EVERY- warning, hint, note (not a little group) can be mutated to ERROR with $WARN and number.  I have found this feature only doing test. But maybe you knows some internet link on this.


--- Quote ---But thanks for your effort, I might use it under Geany, maybe as a plugin.
OTOH you can also copy out the revelant code from the Lazarus sourcecode.
--- End quote ---

Thanks. Of course the code is the simplest possible, and so everyone can improve.
Although, again, I don't know where is in Lazarus the code that  generate the $WARN directives.

Thaddy:
grep is your friend. And it is disturbing you did not read the documentation:
https://www.freepascal.org/docs-html/current/user/usersu16.html#x39-460005.1.5
"-SeN
The compiler stops after the N-th error. Normally, the compiler tries to continue compiling after an error, until 50 errors are reached, or a fatal error is reached, and then it stops. With this switch, the compiler will stop after the N-th error (if N is omitted, a default of 1 is assumed). Instead of a number, one of n, h or w can also be specified. In that case the compiler will consider notes, hints or warnings as errors and stop when one is encountered.".
Why is that so difficult to read?  >:D >:D

gidesa:

--- Quote from: Thaddy on April 05, 2024, 06:36:14 pm ---Why is that so difficult to read?  >:D >:D

--- End quote ---

Auto-quote:

--- Quote ---I don't have found any documentation on the fact that -EVERY- warning, hint, note (not a little group) can be mutated to ERROR with $WARN and number.
--- End quote ---

Have I wrote "with command line switch" ??? No.
Entirely different things.


Navigation

[0] Message Index

Go to full version