Recent

Author Topic: Promote warnings to errors  (Read 1501 times)

gidesa

  • Jr. Member
  • **
  • Posts: 87
Promote warnings to errors
« on: April 01, 2024, 01:04:42 pm »
Hello,
 in Delphi you can "promote" warnings to errors (or ignore them, too).
You can do that from the IDE, or with directives as:
{$WARN   UNSAFE_CODE   ERROR}
(other that ON or OFF).
I think this is an useful feature, that could be added to FPC/Lazarus.

dsiders

  • Hero Member
  • *****
  • Posts: 1153
Re: Promote warnings to errors
« Reply #1 on: April 01, 2024, 04:17:40 pm »
Hello,
 in Delphi you can "promote" warnings to errors (or ignore them, too).
You can do that from the IDE, or with directives as:
{$WARN   UNSAFE_CODE   ERROR}
(other that ON or OFF).
I think this is an useful feature, that could be added to FPC/Lazarus.

It already exists for some messages/identifiers:

https://www.freepascal.org/docs-html/prog/progsu80.html
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Thaddy

  • Hero Member
  • *****
  • Posts: 14850
  • Censorship about opinions does not belong here.
Re: Promote warnings to errors
« Reply #2 on: April 01, 2024, 04:38:29 pm »
You can compile with -Sew which means treat warnings as errors: this is the way fpc itself is compiled.(the compiler and the rtl, not the packages)
You can also compile with -Sewh too: even hints will be treated as errors.
The latter is a bit over the top, but compiling with -Sew is highly recommended. Note that in many cases, you want to turn off a certain warning, because -Sew is very strict. Sometimes too strict.
FPC could do that long before Delphi could.
IOW FPC can do a lot more and more precise than Delphi can.
« Last Edit: April 01, 2024, 04:42:23 pm by Thaddy »
Remember the Medway disaster..

gidesa

  • Jr. Member
  • **
  • Posts: 87
Re: Promote warnings to errors
« Reply #3 on: April 01, 2024, 05:31:13 pm »

It already exists for some messages/identifiers:

https://www.freepascal.org/docs-html/prog/progsu80.html

Wow, thank you! I was confused because in Lazarus the page Options/Messages is similar to the Delphi one, but without the Error option.
But they are very few. In Lazarus messages list there are many more possible warnings. 
« Last Edit: April 01, 2024, 05:43:40 pm by gidesa »

gidesa

  • Jr. Member
  • **
  • Posts: 87
Re: Promote warnings to errors
« Reply #4 on: April 01, 2024, 05:35:32 pm »
You can compile with -Sew which means treat warnings as errors: this is the way fpc itself is compiled.(the compiler and the rtl, not the packages)
You can also compile with -Sewh too: even hints will be treated as errors.
The latter is a bit over the top, but compiling with -Sew is highly recommended. Note that in many cases, you want to turn off a certain warning, because -Sew is very strict. Sometimes too strict.
FPC could do that long before Delphi could.
IOW FPC can do a lot more and more precise than Delphi can.

Thank you!
By the way, the image is from Delphi XE2 of 2011. Maybe FPC had this feature before that 2011.

 
« Last Edit: April 01, 2024, 05:42:32 pm by gidesa »

Thaddy

  • Hero Member
  • *****
  • Posts: 14850
  • Censorship about opinions does not belong here.
Re: Promote warnings to errors
« Reply #5 on: April 01, 2024, 05:58:22 pm »
since 2 series. So yes, way before 2011.
Remember the Medway disaster..

gidesa

  • Jr. Member
  • **
  • Posts: 87
Re: Promote warnings to errors
« Reply #6 on: April 01, 2024, 06:03:16 pm »
2002

Ok. But I see one difference: in Delphi -all- warnings can be selectively set on/off/error, with IDE or directives.
In FPC all can be set on/off, but -only in IDE-. And only a limited group can be  set to on/off/error with directive.
So in Delphi you have more fine grained control.

Thaddy

  • Hero Member
  • *****
  • Posts: 14850
  • Censorship about opinions does not belong here.
Re: Promote warnings to errors
« Reply #7 on: April 01, 2024, 06:05:53 pm »
There is no difference. In fpc you can turn of any particular warning or hint. Or all of them. so it is the opposite. FPC can even turn off notes: -Sewhn.
all of these are governed by numbers, like {$warn 5024 off} but these numbers are easy to come by and that switch is for warnings, hints and notes. I - and others - already explained that on this forum for, well, since Methusalem.
In Lazarus it can even be done through a dialog, where you can pick and choose and you do not have to rely on the numbers.
The dialog is under project options|compiler|messages.
You can turn off or on all hints, warnings and notes.
But FreePascal can do even better, because it allows you to switch them off or on for just a tiny fragment of code, using {$push} and {$pop}, which has also be explained many times.
The latter relies on the programmer, not the dialog settings, because these are global.
And you can't do that in Delphi.

« Last Edit: April 01, 2024, 06:30:17 pm by Thaddy »
Remember the Medway disaster..

gidesa

  • Jr. Member
  • **
  • Posts: 87
Re: Promote warnings to errors
« Reply #8 on: April 01, 2024, 07:31:26 pm »
No, it's different.
Please see,  in my first post  I am writing about "promote warns to errors" (and same in title, and with image if not clear the phrase...),
Not about switching on/off *all* warns.
You wrote on -Sew that promote *all* warns to errors, thanks, it's a starting point.

Edit: I tried to use "error" in direcive for a generic warn, for example:
{$Warn 5037 error}
This works fine! Although not documented.
So the IDE could be improved to display the 3 options for every warn: on, off, error.
 


 
« Last Edit: April 01, 2024, 07:57:06 pm by gidesa »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5548
  • Compiler Developer
Re: Promote warnings to errors
« Reply #9 on: April 07, 2024, 10:37:00 pm »
Edit: I tried to use "error" in direcive for a generic warn, for example:
{$Warn 5037 error}
This works fine! Although not documented.

Did you really read the documentation?

 

TinyPortal © 2005-2018