I am requesting a pragma to suppress warnings that match a given regular expression. (Really I'd be happy with any way to suppress arbitrary warnings for small sections of code. This is just my proposal of a simple way to do it.)
I propose adding two new pragmas: #pragma start_no_warn_regex [regular expression here to end of line] and #pragma end_no_warn_regex When the preprocessor encounters start_no_warn_regex, it pushes the regular expression onto a stack of regular expressions. When it encounters end_no_warn_regex, it pops the top regex off the stack. Then for any line of code, if a warning would be emitted that matches any regex in the stack, that warning is suppressed. -------- - Why? - -------- Warnings, by definition are going to have false positives. However, after one has looked carefully at the case in question (through a code-review or whatever other quality assurance procedures are in place) and decided that the code as written is good, the warning becomes noise needing to be mentally filtered out by the programmer each time and possibly obscuring new warnings that should be heeded. This can be especially burdensome in library code. One may have a complex templated class in a header that compiles correctly but which produces warnings. The library should not emit warnings because the user can not fix the problem. However, giving the compiler enough analysis force to avoid spitting out the warning is impractical. It is better for the compiler to flag suspicious things that are tractable to find and allow the human analytical skills to fill in the gap. Some warnings can be handled by simple code changes: I leave out the names of variables in function calls where the variable is unused; I initialize some variables in unreachable code that the compiler does not know is unreachable; I initialize others twice to avoid warnings about "possible use of x uninitialized." and so forth. However, I would like a general method of warning suppression and #pragma start_no_warn_regex provides an easy and powerful way of meeting this goal. (Of course choose a shorter name if you'd like, the effect is what I'm interested in.) Disabling warnings for an entire compilation unit is the other way to attack this problem. However, it is too blunt a tool. I only know that variable x is not being used uninitialized on line y. Variable q on line r of the same routine may be genuinely uninitialized and I would still like to be warned about but not told that variable x is possibly uninitialized. -- Summary: [Feature request] #pragma start_no_warn_regex Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: eric_moyer at yahoo dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45203