public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45203]  New: [Feature request] #pragma start_no_warn_regex
@ 2010-08-05 23:07 eric_moyer at yahoo dot com
  2010-08-05 23:08 ` [Bug c++/45203] " eric_moyer at yahoo dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: eric_moyer at yahoo dot com @ 2010-08-05 23:07 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/45203] [Feature request] #pragma start_no_warn_regex
  2010-08-05 23:07 [Bug c++/45203] New: [Feature request] #pragma start_no_warn_regex eric_moyer at yahoo dot com
@ 2010-08-05 23:08 ` eric_moyer at yahoo dot com
  2010-08-05 23:17 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: eric_moyer at yahoo dot com @ 2010-08-05 23:08 UTC (permalink / raw)
  To: gcc-bugs



-- 

eric_moyer at yahoo dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
            Summary|[Feature request] #pragma   |[Feature request] #pragma
                   |start_no_warn_regex         |start_no_warn_regex


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45203


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/45203] [Feature request] #pragma start_no_warn_regex
  2010-08-05 23:07 [Bug c++/45203] New: [Feature request] #pragma start_no_warn_regex eric_moyer at yahoo dot com
  2010-08-05 23:08 ` [Bug c++/45203] " eric_moyer at yahoo dot com
@ 2010-08-05 23:17 ` pinskia at gcc dot gnu dot org
  2010-08-06  2:09 ` eric_moyer at yahoo dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-08-05 23:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-08-05 23:17 -------
Starting with 4.5 you can disable a class of warnings in the source.  This is
better than a regular expression as it is safe for internationalization.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45203


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/45203] [Feature request] #pragma start_no_warn_regex
  2010-08-05 23:07 [Bug c++/45203] New: [Feature request] #pragma start_no_warn_regex eric_moyer at yahoo dot com
  2010-08-05 23:08 ` [Bug c++/45203] " eric_moyer at yahoo dot com
  2010-08-05 23:17 ` pinskia at gcc dot gnu dot org
@ 2010-08-06  2:09 ` eric_moyer at yahoo dot com
  2010-08-09 21:28 ` pinskia at gcc dot gnu dot org
  2010-08-09 22:10 ` eric_moyer at yahoo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: eric_moyer at yahoo dot com @ 2010-08-06  2:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from eric_moyer at yahoo dot com  2010-08-06 02:09 -------
If you are talking about "#pragma GCC diagnostic" that looks good.  Turning off
error classes is sufficiently fine grained.  However the pragma is only 
guaranteed to work on a file-wide scope.  The 4.5 manual says,

"Also, while it is syntactically valid to put these pragmas anywhere in your
sources, the only supported location for them is before any data or functions
are defined. Doing otherwise may result in unpredictable results depending on
how the optimizer manages your sources."

I want to disable warnings for particular lines of code rather than whole
files.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45203


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/45203] [Feature request] #pragma start_no_warn_regex
  2010-08-05 23:07 [Bug c++/45203] New: [Feature request] #pragma start_no_warn_regex eric_moyer at yahoo dot com
                   ` (2 preceding siblings ...)
  2010-08-06  2:09 ` eric_moyer at yahoo dot com
@ 2010-08-09 21:28 ` pinskia at gcc dot gnu dot org
  2010-08-09 22:10 ` eric_moyer at yahoo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-08-09 21:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2010-08-09 21:28 -------
(In reply to comment #2)
> I want to disable warnings for particular lines of code rather than whole
> files.

See
http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas

And 
http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01255.html

This has already been fixed for 4.6.0.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45203


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/45203] [Feature request] #pragma start_no_warn_regex
  2010-08-05 23:07 [Bug c++/45203] New: [Feature request] #pragma start_no_warn_regex eric_moyer at yahoo dot com
                   ` (3 preceding siblings ...)
  2010-08-09 21:28 ` pinskia at gcc dot gnu dot org
@ 2010-08-09 22:10 ` eric_moyer at yahoo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: eric_moyer at yahoo dot com @ 2010-08-09 22:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from eric_moyer at yahoo dot com  2010-08-09 22:10 -------
That is great to hear.  I've wanted this feature for years (but never took the
time to create a bugzilla account.)  Thank you.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45203


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-08-09 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-05 23:07 [Bug c++/45203] New: [Feature request] #pragma start_no_warn_regex eric_moyer at yahoo dot com
2010-08-05 23:08 ` [Bug c++/45203] " eric_moyer at yahoo dot com
2010-08-05 23:17 ` pinskia at gcc dot gnu dot org
2010-08-06  2:09 ` eric_moyer at yahoo dot com
2010-08-09 21:28 ` pinskia at gcc dot gnu dot org
2010-08-09 22:10 ` eric_moyer at yahoo dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).