public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Desire gcc option to skip warnings in standard headers
@ 1998-06-26 13:03 Frederick W. Wheeler
  1998-06-29  8:41 ` Branko Cibej
  0 siblings, 1 reply; 16+ messages in thread
From: Frederick W. Wheeler @ 1998-06-26 13:03 UTC (permalink / raw)
  To: egcs

It would be very convenient for me to have a gcc command-line option
or #pragma to prevent the printing of warnings in the standard
headers.  Warnings could begin to be issued at the first line that is
not #include <something.h>.  It seems to me that this would be
relatively easy to implement.

For example, in the following code I would like to have an option to
print no warnings until line 3 (which is blank).

1   #include <stream.h>
2   #include <math.h>
3
4   #include "myheader.h"

Of course, once warning begin to be printed, references back to lines
in the standard headers should be printed.

I use almost all of the gcc -W* options to lintify my code.  I have to
resort to a clumsy grep command to get rid of the deluge of warnings
occuring in the standard headers.

I am grateful to the people who have developed gcc and egcs.  These
are great systems.  Thanks for your hard work.

Regards,
Fred Wheeler

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-29  8:41 ` Branko Cibej
@ 1998-06-29  8:41   ` Carlo Wood
  1998-06-29  8:41     ` Branko Cibej
  1998-06-29  9:38   ` Branko Cibej
  1 sibling, 1 reply; 16+ messages in thread
From: Carlo Wood @ 1998-06-29  8:41 UTC (permalink / raw)
  To: Branko Cibej; +Cc: egcs

| Here's a simple patch that inhibits warnings generated in system headers
| unless '-Wsystem-headers' is specified. It doesn't attempt to handle
| warnings generated by cccp or cpplib yet.
| 
| Comments, anybody? Is this the right way to do it?

I don't like this, I think the new option should turn
warning off if used, but by default give warnings for
system headers too.

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-26 13:03 Desire gcc option to skip warnings in standard headers Frederick W. Wheeler
@ 1998-06-29  8:41 ` Branko Cibej
  1998-06-29  8:41   ` Carlo Wood
  1998-06-29  9:38   ` Branko Cibej
  0 siblings, 2 replies; 16+ messages in thread
From: Branko Cibej @ 1998-06-29  8:41 UTC (permalink / raw)
  To: egcs, egcs-patches

Frederick W. Wheeler wrote:

> It would be very convenient for me to have a gcc command-line option
> or #pragma to prevent the printing of warnings in the standard
> headers.  Warnings could begin to be issued at the first line that is
> not #include <something.h>.  It seems to me that this would be
> relatively easy to implement.

Here's a simple patch that inhibits warnings generated in system headers
unless '-Wsystem-headers' is specified. It doesn't attempt to handle
warnings generated by cccp or cpplib yet.

Comments, anybody? Is this the right way to do it?

--
Branko Cibej   <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49  fax: (++386 61) 186 52 70

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-29  8:41   ` Carlo Wood
@ 1998-06-29  8:41     ` Branko Cibej
  1998-06-29 20:41       ` Carlo Wood
  1998-06-30  0:42       ` Jeffrey A Law
  0 siblings, 2 replies; 16+ messages in thread
From: Branko Cibej @ 1998-06-29  8:41 UTC (permalink / raw)
  To: Carlo Wood; +Cc: egcs

Carlo Wood wrote:

> | Comments, anybody? Is this the right way to do it?
>
> I don't like this, I think the new option should turn
> warning off if used, but by default give warnings for
> system headers too.

That's trivial to do, of course -- most probably I should just invert the
meaning of the option. What about the name of the option, though? I don't like
-W(no-)system-headers, even though I thought it up myself...

--
Branko Cibej   <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49  fax: (++386 61) 186 52 70



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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-29  8:41 ` Branko Cibej
  1998-06-29  8:41   ` Carlo Wood
@ 1998-06-29  9:38   ` Branko Cibej
  1 sibling, 0 replies; 16+ messages in thread
From: Branko Cibej @ 1998-06-29  9:38 UTC (permalink / raw)
  To: egcs, egcs-patches

Branko Cibej wrote:

> Frederick W. Wheeler wrote:
>
> > It would be very convenient for me to have a gcc command-line option
> > or #pragma to prevent the printing of warnings in the standard
> > headers.  Warnings could begin to be issued at the first line that is
> > not #include <something.h>.  It seems to me that this would be
> > relatively easy to implement.
>
> Here's a simple patch that inhibits warnings generated in system headers
> unless '-Wsystem-headers' is specified. It doesn't attempt to handle
> warnings generated by cccp or cpplib yet.

Here's another patch, this one handles cccp.

> Comments, anybody? Is this the right way to do it?

(Yes, yes, cut-and-paste programming and no changelog entries, but I'm just
playing around for the moment).

--
Branko Cibej   <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49  fax: (++386 61) 186 52 70

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-29  8:41     ` Branko Cibej
@ 1998-06-29 20:41       ` Carlo Wood
  1998-06-30  0:00         ` Jeffrey A Law
  1998-06-30  0:42         ` Branko Cibej
  1998-06-30  0:42       ` Jeffrey A Law
  1 sibling, 2 replies; 16+ messages in thread
From: Carlo Wood @ 1998-06-29 20:41 UTC (permalink / raw)
  To: Branko Cibej; +Cc: egcs

| > I don't like this, I think the new option should turn
| > warning off if used, but by default give warnings for
| > system headers too.
| 
| That's trivial to do, of course -- most probably I should just invert the
| meaning of the option. What about the name of the option, though? I don't like
| -W(no-)system-headers, even though I thought it up myself...

Hmm, it appears to be not logical...
Looking at most other -W options.

A #pragma seems more logical, and more flexible too.

Other compilers allow to turn off each type of
warning seperately with a #pragma, which would be
the ideal.  It would introduce a boolean for each type
of warning, and I imagine we need an array for that:
An array that contains these variables, and the warnings
and some code that is used.

struct warning {
  short warn_code;
  const char *format;
  unsigned int flags;	// Contains flag to turn it on/off with a #pragma
};

enum {
  warnFoo
  ...
};

struct warning warnings[] = {
  { warnFoo, "You're not allowed to foo around: %s", pendanticWarning },
  ...

...

  print_warning(warnFoo, error);

...


Doesn't that look nice? :)

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-29 20:41       ` Carlo Wood
@ 1998-06-30  0:00         ` Jeffrey A Law
  1998-06-30  9:03           ` Andi Kleen
  1998-06-30 23:15           ` Mumit Khan
  1998-06-30  0:42         ` Branko Cibej
  1 sibling, 2 replies; 16+ messages in thread
From: Jeffrey A Law @ 1998-06-30  0:00 UTC (permalink / raw)
  To: Carlo Wood; +Cc: Branko Cibej, egcs

  In message < 199806291617.SAA24744@jolan.ppro >you write:
  > A #pragma seems more logical, and more flexible too.
pragmas are generally frowned upon in gcc.  You'll have a hard time
convincing anyone to accept new ones.

jeff

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-29  8:41     ` Branko Cibej
  1998-06-29 20:41       ` Carlo Wood
@ 1998-06-30  0:42       ` Jeffrey A Law
  1998-06-30  9:03         ` Branko Cibej
  1 sibling, 1 reply; 16+ messages in thread
From: Jeffrey A Law @ 1998-06-30  0:42 UTC (permalink / raw)
  To: Branko Cibej; +Cc: Carlo Wood, egcs

  In message < 3597B270.EC811EB4@hermes.si >you write:
  > Carlo Wood wrote:
  > 
  > > | Comments, anybody? Is this the right way to do it?
  > >
  > > I don't like this, I think the new option should turn
  > > warning off if used, but by default give warnings for
  > > system headers too.
  > 
  > That's trivial to do, of course -- most probably I should just invert the
  > meaning of the option. What about the name of the option, though? I don't like
  > -W(no-)system-headers, even though I thought it up myself...
Warnings should be enabled by -W<foo> and disabled by -Wno-<foo>.  I'm
not aware of any that do not follow that convention and I don't think we
should start making any now :-)

The default behavior can either be on or off, that's separate from 
making -W<foo> and -Wno-<foo> do the right thing.

jeff

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-29 20:41       ` Carlo Wood
  1998-06-30  0:00         ` Jeffrey A Law
@ 1998-06-30  0:42         ` Branko Cibej
  1 sibling, 0 replies; 16+ messages in thread
From: Branko Cibej @ 1998-06-30  0:42 UTC (permalink / raw)
  To: Carlo Wood; +Cc: egcs

Carlo Wood wrote:

> A #pragma seems more logical, and more flexible too.
>
> Other compilers allow to turn off each type of
> warning seperately with a #pragma, which would be
> the ideal.  It would introduce a boolean for each type
> of warning, and I imagine we need an array for that:
> An array that contains these variables, and the warnings
> and some code that is used.

Och aye, I know a certain compiler that does that. The feature is used widely in the
rather broken libraries shipped with said compiler...

Anyway, I agree with Jeff that #pragmas are not the way to go. One does want to
write portable code once in a while.[skip some very non-egcs-ish example code]

> ...
>
> Doesn't that look nice? :)

Beautiful, and I'm sure you'd be willing to spend some time to modify egcs in this
manner :->

--
Branko Cibej   <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49  fax: (++386 61) 186 52 70



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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-30  0:00         ` Jeffrey A Law
@ 1998-06-30  9:03           ` Andi Kleen
  1998-07-01  0:54             ` Carlo Wood
  1998-06-30 23:15           ` Mumit Khan
  1 sibling, 1 reply; 16+ messages in thread
From: Andi Kleen @ 1998-06-30  9:03 UTC (permalink / raw)
  To: law; +Cc: egcs

In message < 15759.899189718@hurl.cygnus.com >you write:
>
>  In message < 199806291617.SAA24744@jolan.ppro >you write:
>  > A #pragma seems more logical, and more flexible too.
>pragmas are generally frowned upon in gcc.  You'll have a hard time
>convincing anyone to accept new ones.

Many of the reasons why pragmas are disliked (not usable in macros
etc.) are gone with the ISO C9x _Pragma() construct. Of course there
could be still name collisions of pragma names with other compilers, 
but that can be easily fixed which a #ifdef (and __attribute__ needs 
#ifdef magic too)


-Andi


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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-30  0:42       ` Jeffrey A Law
@ 1998-06-30  9:03         ` Branko Cibej
  0 siblings, 0 replies; 16+ messages in thread
From: Branko Cibej @ 1998-06-30  9:03 UTC (permalink / raw)
  To: law; +Cc: Carlo Wood, egcs

Jeffrey A Law wrote:

>   > That's trivial to do, of course -- most probably I should just invert the
>   > meaning of the option. What about the name of the option, though? I don't like
>   > -W(no-)system-headers, even though I thought it up myself...
> Warnings should be enabled by -W<foo> and disabled by -Wno-<foo>.  I'm
> not aware of any that do not follow that convention and I don't think we
> should start making any now :-)
>
> The default behavior can either be on or off, that's separate from
> making -W<foo> and -Wno-<foo> do the right thing.

Right. The attached patches don't change the default behaviour, but inhibit warnings
from system headers if -Wno-system-headers. The patch for cpplib is separate because I
haven't really tested it -- I'd have to reconfigure the compiler. BTW, the patches are
against the latest snapshot.

--
Branko Cibej   <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49  fax: (++386 61) 186 52 70

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-30  0:00         ` Jeffrey A Law
  1998-06-30  9:03           ` Andi Kleen
@ 1998-06-30 23:15           ` Mumit Khan
  1998-07-01 20:15             ` Raja R Harinath
  1 sibling, 1 reply; 16+ messages in thread
From: Mumit Khan @ 1998-06-30 23:15 UTC (permalink / raw)
  To: Jeffrey A Law; +Cc: egcs

On Tue, 30 Jun 1998, Jeffrey A Law wrote:

> 
> pragmas are generally frowned upon in gcc.  You'll have a hard time
> convincing anyone to accept new ones.
> 

And for good reasons in most cases. However, what if the native API
requires it (especially if the native headers are unusable w/out it)?

Now I'm having second thoughts submitting patches for Win32 specific
pragmas (sysv like #pragma pack with a slight twist, and also push/pop 
of packing stack) ... these are all necessary thanks to you know who.

Mumit


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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-30  9:03           ` Andi Kleen
@ 1998-07-01  0:54             ` Carlo Wood
  0 siblings, 0 replies; 16+ messages in thread
From: Carlo Wood @ 1998-07-01  0:54 UTC (permalink / raw)
  To: andi; +Cc: egcs

| >  > A #pragma seems more logical, and more flexible too.
| >pragmas are generally frowned upon in gcc.  You'll have a hard time
| >convincing anyone to accept new ones.
| 
| Many of the reasons why pragmas are disliked (not usable in macros
| etc.) are gone with the ISO C9x _Pragma() construct. Of course there
| could be still name collisions of pragma names with other compilers, 
| but that can be easily fixed which a #ifdef (and __attribute__ needs 
| #ifdef magic too)

The reason I thought about #pragma's is because it is more flexible:
allows to turn on and off particular warnings at any line number.
The use of -Woptions are effective for every file and line number.

I don't really care to have the possibility to turn warnings on and off
though, except when it is impossible to write good code that doesn't
cause the warning.  I always use -Wall -Woverloaded-virtual
-Wpointer-arith -Winline -Werror anyway.
There are only a few cases sometimes a bit annoying, like the
"might be used uninitialized".

Having broken system headers is of course a whole different story:
Not everyone is sys admin and able to fix them.

The -Wno-system-headers is actually very good solution to real
problem as originally posted :).

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-06-30 23:15           ` Mumit Khan
@ 1998-07-01 20:15             ` Raja R Harinath
  0 siblings, 0 replies; 16+ messages in thread
From: Raja R Harinath @ 1998-07-01 20:15 UTC (permalink / raw)
  To: egcs

Mumit Khan <khan@xraylith.wisc.edu> writes:
> On Tue, 30 Jun 1998, Jeffrey A Law wrote:
> > pragmas are generally frowned upon in gcc.  You'll have a hard time
> > convincing anyone to accept new ones.
> 
> And for good reasons in most cases. However, what if the native API
> requires it (especially if the native headers are unusable w/out it)?

Isn't that what `fixincludes' is meant for.

- Hari
-- 
Raja R Harinath ------------------------------ harinath@cs.umn.edu
"When all else fails, read the instructions."      -- Cahn's Axiom
"Our policy is, when in doubt, do the right thing."   -- Roy L Ash

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

* Re: Desire gcc option to skip warnings in standard headers
  1998-07-01 20:15 ` Nathan Myers
@ 1998-07-04 12:40   ` Joseph H. Buehler
  0 siblings, 0 replies; 16+ messages in thread
From: Joseph H. Buehler @ 1998-07-04 12:40 UTC (permalink / raw)
  To: egcs

> It would be very convenient for me to have a gcc command-line option
> or #pragma to prevent the printing of warnings in the standard
> headers.  Warnings could begin to be issued at the first line that is
> not #include <something.h>.  It seems to me that this would be
> relatively easy to implement.

If this gets implemented in gcc, I suggest a better way to define
"system header" than "presence of #include<> syntax".

Where I work, we *never* use

    #include "whatever.h"

because developers compile their files against a shared nightly build
area.  Consider having a .c file in the shared area and a .h file
being edited in your private work area.  Some vendors' compilers, when
compiling the .c file, will *always* look for the .h in the directory
containing the .c file: there is no way to override this.

So we always use the <> syntax so we have complete control over the
include file path.

Joe Buehler

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

* Re: Desire gcc option to skip warnings in standard headers
       [not found] <9806261352.AA18188.cygnus.egcs@ipl.rpi.edu>
@ 1998-07-01 20:15 ` Nathan Myers
  1998-07-04 12:40   ` Joseph H. Buehler
  0 siblings, 1 reply; 16+ messages in thread
From: Nathan Myers @ 1998-07-01 20:15 UTC (permalink / raw)
  To: egcs

Frederick W. Wheeler wrote:
> 
> It would be very convenient for me to have a gcc command-line option
> or #pragma to prevent the printing of warnings in the standard
> headers.  Warnings could begin to be issued at the first line that is
> not #include <something.h>.  It seems to me that this would be
> relatively easy to implement.

Note that not all warnings are undesirable even from very bad headers.

In particular, a warning that a macro is being redefined helps protect
you when non-system-header code defines a macro that is (re)defined in
a system header.  System headers don't tend to do this to themselves,
so emitting the warning anyway would usually be a Good Thing.

Nathan Myers
ncm@cantrip.org

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

end of thread, other threads:[~1998-07-04 12:40 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-26 13:03 Desire gcc option to skip warnings in standard headers Frederick W. Wheeler
1998-06-29  8:41 ` Branko Cibej
1998-06-29  8:41   ` Carlo Wood
1998-06-29  8:41     ` Branko Cibej
1998-06-29 20:41       ` Carlo Wood
1998-06-30  0:00         ` Jeffrey A Law
1998-06-30  9:03           ` Andi Kleen
1998-07-01  0:54             ` Carlo Wood
1998-06-30 23:15           ` Mumit Khan
1998-07-01 20:15             ` Raja R Harinath
1998-06-30  0:42         ` Branko Cibej
1998-06-30  0:42       ` Jeffrey A Law
1998-06-30  9:03         ` Branko Cibej
1998-06-29  9:38   ` Branko Cibej
     [not found] <9806261352.AA18188.cygnus.egcs@ipl.rpi.edu>
1998-07-01 20:15 ` Nathan Myers
1998-07-04 12:40   ` Joseph H. Buehler

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).