public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: RFC: Named warnings
@ 2003-01-24 22:25 Robert Dewar
  2003-01-24 22:58 ` Neil Booth
  2003-01-25  0:34 ` Oscar Fuentes
  0 siblings, 2 replies; 88+ messages in thread
From: Robert Dewar @ 2003-01-24 22:25 UTC (permalink / raw)
  To: dewar, neil; +Cc: gcc, shebs

> No, an implementor can add as many warnings as she wants.  The standards
> only dictate what must be diagnosed.
> 
> Regardless, what has that to do with my post?

I was responding to the comment that some warnings should be made into errors.
That is not a transformation that is up to the individual implementor.

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-25  9:40 Robert Dewar
  0 siblings, 0 replies; 88+ messages in thread
From: Robert Dewar @ 2003-01-25  9:40 UTC (permalink / raw)
  To: mark, neil; +Cc: dj, gcc, shebs

> For example, the current trigraph warnings explicitly contain the
> trigraph.  That's unnecessary when a caret is pointing right at it.
> Similarly for all the union/struct/enum separated diagnostics in the
> front end at the moment.

I would not be too hasty in this assessment. GNAT does an excellent job of
placing warnings in exactly the right place, but we still find most people
prefer to work in brief error message mode without the carets, so it is
still useful to have appropriate redundant insertions in the messages.

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-25  2:06 Robert Dewar
  2003-01-25  6:53 ` Oscar Fuentes
  0 siblings, 1 reply; 88+ messages in thread
From: Robert Dewar @ 2003-01-25  2:06 UTC (permalink / raw)
  To: gcc, ofv

> The C++ standard, IIRC, says nothing about "warning" or "error"
> messages. It talks about "diagnostics". You can turn everything into
> warnings, always generate an object file and you are ok as far as the
> standard is concerned. What is a warning or an error is a QoI
> issue. OTOH, a good C++ compiler reports far many more diagnostics
> (errors and warnings) than the standard requires.

Yes, but you must at least have a mode where you generate diagnostics
only for those things which C++ declares as wrong. I do not agree that
a good C++ compiler generates more errors than the standard requires.
This seems totally wrong to me. A program that is correct by the rules
of the C++ standard should be able to compile diagnostic free in any
decent compiler (typically by turning off warnings).

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 23:03 Robert Dewar
  0 siblings, 0 replies; 88+ messages in thread
From: Robert Dewar @ 2003-01-24 23:03 UTC (permalink / raw)
  To: dewar, neil; +Cc: gcc, shebs

> I didn't say that.  I said more of our warnings should be errors.  The
> example I gave was


OK, well if you are restricting this to warnings about extensions, we of
course have complete freedom to define them the way we want, though any
change in the implentation should be reflected in the documentation.

The mere fact that code is nonsensical does not mean that you can give
an error, if it is something that the standard does not proscribe.

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 21:40 Robert Dewar
  2003-01-24 21:43 ` Neil Booth
  0 siblings, 1 reply; 88+ messages in thread
From: Robert Dewar @ 2003-01-24 21:40 UTC (permalink / raw)
  To: dewar, neil; +Cc: gcc, shebs

> Huh?

Whether something is a warning or not is dictated by the C and C++ standards,
it is not something that is up to the implementor.

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 21:39 Bruce Korb
  0 siblings, 0 replies; 88+ messages in thread
From: Bruce Korb @ 2003-01-24 21:39 UTC (permalink / raw)
  To: DJ Delorie, gcc

> > Present code:
> > 
> >           /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type
> >              and this is a function, or if -Wimplicit; prefer the former
> >              warning since it is more explicit.  */
> >           if ((warn_implicit_int || warn_return_type || flag_isoc99)
> >               && funcdef_flag)
> >             warn_about_return_type = 1;
> >           else if (warn_implicit_int || flag_isoc99)
> >             pedwarn_c99 ("type defaults to `int' in declaration of `%s'",
> >                          name);
> 
> I would think something like this:
> 
>         warn ("functions.retval.type-defaults", "...");
> 
> And somewhere *else* we figure out whether this warning should be
> enabled or not based on the c89/c99/pedantic/-W options.

Wouldn't this be simpler?

  /*=warn type-defaults-to-int
   * fmt:   "type defaults to `int' in declaration of `%s'"
   * group: pedantic isoc99 return-type funcdef
   * disabled:
   * doc:   No return type was specified for your procedure.
   *        You should type it explicitly to "int", if it returns an int,
   *        or set it to void if no value is returned.
  =*/
  WARN_TYPE_DEFAULTS_TO_INT( name );

And, elsewhere you have - generated - :

  #define WARN_ID_TYPE_DEFAULTS_TO_INT  <<some-number>>
  #define WARN_TYPE_DEFAULTS_TO_INT( a1 ) \
     if (warn_enabled[ WARN_ID_TYPE_DEFAULTS_TO_INT ]) \
         warning ("type defaults to `int' in declaration of `%s'", \
                   (a1) );

and a bit of initialization code that turns on the warnings related
to "pedantic", "isoc99", "return-type" and "funcdef" -- including
the entry for WARN_ID_TYPE_DEFAULTS_TO_INT

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 20:50 Bruce Korb
  0 siblings, 0 replies; 88+ messages in thread
From: Bruce Korb @ 2003-01-24 20:50 UTC (permalink / raw)
  To: Stan Shebs; +Cc: gcc


Hi Stan,

> That's certainly my #1 implementation consideration - how to get there
> incrementally.  One of the things I'd want to set up would be some
> kind of auditing script that anybody could run to see how far along
> things are.  New warning controls should be made so they're an easy
> bit for newbies to add too.

I would like you to consider my toy for implementation.
Bundled with autogen is a comment extractor much akin to Java Doc
that should facilitate newbie use.  It could work something like this,
in the GCC source code:

  /*=warn mumble
   * fmt: "some sort of format string:  %d"
   * group: pedantic all
   * disabled:
   * doc:  why you got this warning
   *       and what you might do about it.
  =*/
  WARN_MUMBLE( arg );

From that, the following things could be made to happen:

1.  The "mumble" warning is normally disabled.  This would be accomplished
    inside the #define-d code for the WARN_MUMBLE macro.  Note that the
    WARN_MUMBLE takes one argument and that information can be derived by
    scanning the "fmt" string for formatting commands ("%d").

2.  It would be enabled if any of -Wmumble -Wall -Wpedantic were set
    on the command line

3.  An enumeration of all warnings would be emitted
    An array of warning states can be maintained via this enumeration,
    including push/pop/initial state/current state/whatever.

4.  A table to map warning names to the enumeration value would be emitted.

5.  If the "mumble" warning were needed elsewhere, it can be used there,
    just omit the special comment.

6.  For debugging purposes, the emitted WARN_MUMBLE macro could include
    the file and line number where it occurrs, and not for released code. :-)

7.  A "how-to-deal-with-this-warning" document.

8.  Additional attributes can be added, as the need arises.

Basically, you can take those several strings and arrange them into anything
you like.  Very conveniently.  I'll help, if you're interested.  I can't drive
it 'cuz I have a day job....

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 19:12 Robert Dewar
  0 siblings, 0 replies; 88+ messages in thread
From: Robert Dewar @ 2003-01-24 19:12 UTC (permalink / raw)
  To: gdr, jbuck; +Cc: gcc, mark, shebs

> If a -Wxxx causes a warning to be issued in a particular file, then
> it is far easier and less contrived to edit that file and adds
> 
>    #pragma warning xxx [on|off]
> 
> around the offending code than find out the handbook and lookup the
> corresponding number.  We have to take ease of use into account.

That's exactly the gnat approach, except that the pragma is spelled

      pragma Warnings (On | Off);

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 18:02 Paolo Bonzini
  2003-01-24 20:03 ` Stan Shebs
  0 siblings, 1 reply; 88+ messages in thread
From: Paolo Bonzini @ 2003-01-24 18:02 UTC (permalink / raw)
  To: gcc

What
about -Werror-missing-prototype, -Wwarn-missing-prototype, -Wmissing-prototy
pe, -Wno-missing-prototype?  The third would base its behavior on
whether -Werror is specified.  This would avoid overloading -E which runs
cpp now.

Paolo


^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 15:09 Robert Dewar
  2003-01-24 17:15 ` Michael S. Zick
  0 siblings, 1 reply; 88+ messages in thread
From: Robert Dewar @ 2003-01-24 15:09 UTC (permalink / raw)
  To: gcc, kaih

I must say my reaction is that the very fine control over warnings seems
a bit of overkill, but perhaps there is more of a problem with "bad" warnings
in g++ and gnu c than in gnat (I don't have the experience to make that
judgment). In GNAT, we group warnings under about 10 different categories
that can be separately controlled by either compile time switches or by
pragmas that can turn on and off these various categories of warnings.
In addition we have a general facility for turning warnings on and off
with pragmas (all warnings). This has proved quite adequate, and in fact
we have not had any requests at all to provide any more specific control.

The trouble with over-specific control is that warning messages are the
sort of thing that change frequently as they are improved and sharpened,
and you don't want to have people chasing after them by dealing with
new warning codes that now appear in the text of the program.

^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: RFC: Named warnings
@ 2003-01-24 14:44 Robert Dewar
  2003-01-24 20:50 ` Neil Booth
  0 siblings, 1 reply; 88+ messages in thread
From: Robert Dewar @ 2003-01-24 14:44 UTC (permalink / raw)
  To: neil, shebs; +Cc: gcc

> o I think consideration should be made to turning many current warnings
>   into errors.  This will reduce the number of warnings we need to
>   control.  My experience writing my C parser is that I've made many
>   things that were warnings into errors.  Sure, you can warn and do
>   the obvious thing to accept the translation unit, but I tend to
>   lean towards making errors of things that are easily avoided
>   and not stylistic.  e.g. "inline int x;" is currently a warning,
>   and IMO should be an error.  Existing warnings like the struct cpp_reader
>   one in prototypes should of course remain a warning, as there is
>   nothing actually syntactically or semantically incorrect about the usage.

This seems like something that should only be done with a switch, since it
is clearly non-standard. I suppose you could put this under -pedantic, but
in that case you had better be sure that your new "incorrect" errors do not
discombobulate too many correct programs.

^ permalink raw reply	[flat|nested] 88+ messages in thread
* RFC: Named warnings
@ 2003-01-24  2:09 Stan Shebs
  2003-01-24  2:26 ` Zack Weinberg
                   ` (7 more replies)
  0 siblings, 8 replies; 88+ messages in thread
From: Stan Shebs @ 2003-01-24  2:09 UTC (permalink / raw)
  To: gcc

This RFC proposes a uniform system for handling GCC's warnings, based
on the use of names to distinguish every type of warning.  A uniform
system would make every one of GCC's warnings individually
controllable, and enable the use of pragmas and/or attributes to
control warnings within a translation unit.  The following paragraphs
focus on requirements for user-visible behavior - once there is
agreement on the desired behavior, we can then consider how best to
implement.

One of GCC's strengths is the number and variety of its warnings,
which help users by alerting them to possible mistakes in their code,
even for code that is technically correct.  However, GCC's system of
warnings has evolved in a somewhat haphazard fashion.  While most
warnings can be enabled and disabled with a -Wfoo flag, others are
unconditional (such as most warnings relating to attributes), while
others are tied to generic options such as -pedantic, which have other
consequences and can thus be a problem to use.

So as a first step I propose that all of GCC's warnings be made
individually controllable, and that all future warnings always get a
control when they are added to the compiler.

As part of this individual control, each warning will get a unique
name, which consists of an alphanumeric string plus hyphens.  For
existing warnings with controls in the form of -W flags, the names
will correspond to the flag names, so -Wfoo-bar controls the warning
named "foo-bar".  There are no limits on the lengths of warning names,
but "no-" at the beginning of a name is reserved to indicate the
negation of the warning.  ("no-" would not be part of any warning's
name, irrespective of the warning's default value.)

It may still be that some warnings are composites, as with -Wunused,
which controls several other warnings that each have an individual
control, but this is up to the implementation.

It may also be that a single kind of warning will be displayed using
several different messages depending on context; if there is no
plausible reason for enabling one message but not the others, then
they can be combined into a single named warning.  (Since this sort of
merging defeats the purpose of individual control, it should be
uncommon.)

Another frequent request for warnings is that they be changeable
within a translation unit.  Sometimes this is because a warning has
been analyzed and is known to be uninteresting in a particular
context.  Another reason is that additional optimizations are possible
within a translation unit, as is visibility control for private
symbols, so it's undesirable to break one into several units just so
that a -Wno-foo can be applied to a part of the original translation
unit.  Last and perhaps least :-), this feature is provided by
competing compilers, and is expected by users bringing code over from
other platforms.

The obvious way to add fine-grained control is with attributes.  For
instance,

int fn() __attribute__ ((warning ("no-sign-compare", "switch")))
{
  ...
}

would say to warn about any missing cases in switch statements but not
any signed/unsigned conversions within the scope of fn.  The
attributes act as temporary overrides to the global values as
prescribed by compiler defaults and -W flags.  So that warnings' names
need not be constrained by language syntax, they should be expressed
as strings.

Attributes are useful for limiting effect to single functions or
variables, but are unduly repetitive for long files with many
functions and variables.  Pragmas would work better then, as in

#pragma GCC "no-sign-compare" "switch"
...
#pragma GCC "sign-compare" "switch" "missing-prototypes"

which disables signed/unsigned warnings and enables switch case
warnings, then later re-enables the sign warning and also the missing
prototype warning, but with no further effect on switch case warnings.

The effect of each pragma is a one-way change to the warnings listed.
(It would be possible to have warning control pragmas with a push/pop
behavior, but this seems excessive complicated, both to implement and
to use correctly.)

Finally, while -Werror is a useful option, it's difficult to use
reliably in portable software (as witness GCC's own recent travails)
because it affects all enabled warnings.  It just so happens that
-Efoo is not used for anything now, so I propose that -Efoo be defined
to work equivalently to -Wfoo -Werror for warning "foo" only.  There
are complexities with random combos like -Wfoo -Eno-foo -Wno-foo
-Efoo, and these need more thought before implementing.

For all of these extensions, not much additional documentation will be
needed, since it should suffice to document -Wfoo as always, and then
to direct users to remove the "-W" in order to know what names are
available for warning attributes and pragmas.

Stan


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

end of thread, other threads:[~2003-01-29  5:17 UTC | newest]

Thread overview: 88+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-24 22:25 RFC: Named warnings Robert Dewar
2003-01-24 22:58 ` Neil Booth
2003-01-25  0:34 ` Oscar Fuentes
  -- strict thread matches above, loose matches on Subject: below --
2003-01-25  9:40 Robert Dewar
2003-01-25  2:06 Robert Dewar
2003-01-25  6:53 ` Oscar Fuentes
2003-01-24 23:03 Robert Dewar
2003-01-24 21:40 Robert Dewar
2003-01-24 21:43 ` Neil Booth
2003-01-24 21:39 Bruce Korb
2003-01-24 20:50 Bruce Korb
2003-01-24 19:12 Robert Dewar
2003-01-24 18:02 Paolo Bonzini
2003-01-24 20:03 ` Stan Shebs
2003-01-27 21:30   ` Jim Wilson
2003-01-24 15:09 Robert Dewar
2003-01-24 17:15 ` Michael S. Zick
2003-01-24 17:43   ` Andrea 'fwyzard' Bocci
2003-01-24 14:44 Robert Dewar
2003-01-24 20:50 ` Neil Booth
2003-01-24  2:09 Stan Shebs
2003-01-24  2:26 ` Zack Weinberg
2003-01-24  5:15   ` Stan Shebs
2003-01-24  7:17   ` Phil Edwards
2003-01-24 10:27     ` Gabriel Dos Reis
2003-01-24 15:43       ` Phil Edwards
2003-01-24 17:16         ` Gabriel Dos Reis
2003-01-24  3:40 ` Joseph S. Myers
2003-01-24  7:43   ` Stan Shebs
2003-01-24 11:52     ` Kai Henningsen
2003-01-24  7:15 ` Matt Austern
2003-01-24 11:15   ` Gabriel Dos Reis
2003-01-24 21:25     ` Matt Austern
2003-01-24  9:10 ` Neil Booth
2003-01-24 11:49   ` Kai Henningsen
2003-01-24 16:34   ` Phil Edwards
2003-01-24 23:17   ` Geert Bosch
2003-01-24 11:15 ` Mark Mitchell
2003-01-24 11:34   ` Gabriel Dos Reis
2003-01-24 11:56     ` Kai Henningsen
2003-01-24 14:43       ` Gabriel Dos Reis
2003-01-24 17:35       ` Fergus Henderson
2003-01-24 14:24     ` Joseph S. Myers
2003-01-24 15:03       ` Gabriel Dos Reis
2003-01-24 17:57     ` Mark Mitchell
2003-01-24 19:46       ` Stan Shebs
2003-01-24 20:27         ` DJ Delorie
2003-01-24 21:20           ` Joseph S. Myers
2003-01-24 21:27             ` DJ Delorie
2003-01-24 21:39               ` Joseph S. Myers
2003-01-24 23:24           ` Stan Shebs
2003-01-24 23:39             ` DJ Delorie
2003-01-25  0:03             ` Mark Mitchell
2003-01-25  3:21               ` Matt Austern
2003-01-25  3:46                 ` Mark Mitchell
2003-01-25  8:48                   ` Andrea 'fwyzard' Bocci
2003-01-25 10:26                     ` Gabriel Dos Reis
2003-01-25  6:46                 ` Stan Shebs
2003-01-25 14:00                 ` Falk Hueffner
2003-01-25  3:26               ` Neil Booth
2003-01-29  8:18         ` Ben Elliston
2003-01-24 13:11   ` Joseph S. Myers
2003-01-24 15:04     ` Gabriel Dos Reis
2003-01-24 17:58     ` Mark Mitchell
2003-01-24 18:13       ` Falk Hueffner
2003-01-24 18:39         ` Richard Earnshaw
2003-01-24 19:10           ` Gabriel Dos Reis
2003-01-24 19:27             ` Richard Earnshaw
2003-01-24 20:04               ` Gabriel Dos Reis
2003-01-24 20:54         ` Neil Booth
2003-01-24 21:15           ` Tom Tromey
2003-01-24 18:18       ` Joseph S. Myers
2003-01-24 19:05       ` Alexandre Oliva
2003-01-24 15:42   ` Fergus Henderson
2003-01-24 17:23     ` Michael S. Zick
2003-01-24 18:06     ` Mark Mitchell
2003-01-24 18:13       ` Gabriel Dos Reis
2003-01-24 20:23       ` Tom Tromey
2003-01-24 18:11   ` Joe Buck
2003-01-24 18:13     ` Gabriel Dos Reis
2003-01-24 19:49     ` Kevin Handy
2003-01-24 11:42 ` Theodore Papadopoulo
2003-01-24 12:15   ` Joseph S. Myers
2003-01-24 18:49 ` Alexandre Oliva
2003-01-25 10:09 ` Segher Boessenkool
2003-01-25 20:37   ` Fergus Henderson
2003-01-26  5:14     ` Segher Boessenkool
2003-01-26 15:36     ` Nix

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