Is it possible to disable compiler warnings for specific lines?
In C#, this works:
[Obsolete]
class Old { }
#pragma warning disable 612
var oldWithoutWarning = new Old();
#pragma warning restore 612
var oldWithWarning = new Old();
This would be very useful for disabling incomplete pattern matches warnings, especially when a function accepts a particular case of a DU.
You can suppress violations in code using a preprocessor directive, the #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code. Or, you can use the SuppressMessage attribute.
To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx. From the GCC Warning Options: You can request many specific warnings with options beginning -W , for example -Wimplicit to request warnings on implicit declarations.
To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction. Now let's dive into the code for each compiler.
No, the warnings are turned off per-file (or possibly 'from here to the bottom of the file') when using #nowarn
. (Or per compilation/project when using project properties / --nowarn
command-line.)
Since everything is an expression in F# it's not hard to pull out a line or a part of a line and put it in it's own file.
Example of my issue, where ::
pattern matching warned about empty list possiblity, but my state passed to Seq.fold
always has a list with at least one item.
module FoldBookmarks
#nowarn "25"
let foldIntoBookmarks: (string * int * int) seq -> XamlReport.PDF.Bookmark seq =
Seq.fold (fun ((tl,pl,acc)::l) (t,p,_) -> (t,acc,p+acc)::((tl,pl,acc)::l)) [("",0,1)]
>> Seq.map(fun (x,y,_) -> PDF.Bookmark(Title=x, PageNumber= System.Nullable(y)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With