public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines
@ 2020-11-26 23:53 eggert at cs dot ucla.edu
  2020-11-27  0:03 ` [Bug preprocessor/98021] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-11-26 23:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

            Bug ID: 98021
           Summary: #warning issues redundant diagnostic lines
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

I ran into this problem when building something from Gnulib. For the following
program foo.c:

#warning "GCC might issue a bogus -Wreturn-local-addr warning here."
#warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."

The command 'gcc -S foo.c' issues the following diagnostics, which are too
repetitive:

foo.c:1:2: warning: #warning "GCC might issue a bogus -Wreturn-local-addr
warning here." [-Wcpp]
    1 | #warning "GCC might issue a bogus -Wreturn-local-addr warning here."
      |  ^~~~~~~
foo.c:2:2: warning: #warning "See
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>." [-Wcpp]
    2 | #warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
      |  ^~~~~~~

GCC should simply output something like this instead:

foo.c:1:2: warning: GCC might issue a bogus -Wreturn-local-addr warning here.
[-Wcpp]
foo.c:2:2: warning: See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>.
[-Wcpp]

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
@ 2020-11-27  0:03 ` pinskia at gcc dot gnu.org
  2020-11-27  2:14 ` eggert at cs dot ucla.edu
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-11-27  0:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
so you are asking not to show the source file for #warning ?
I don't see why this warning should be treated as any different from any other
warning.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
  2020-11-27  0:03 ` [Bug preprocessor/98021] " pinskia at gcc dot gnu.org
@ 2020-11-27  2:14 ` eggert at cs dot ucla.edu
  2020-11-27  5:34 ` egallager at gcc dot gnu.org
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-11-27  2:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #2 from eggert at cs dot ucla.edu ---
(In reply to Andrew Pinski from comment #1)
> so you are asking not to show the source file for #warning ?

That's the possibility I suggested, yes. Another possibility would be to not
show the diagnostic, and just show the source file. The point is to avoid the
duplication.

> I don't see why this warning should be treated as any different from any
> other warning.

In other warnings, it's useful to show both the diagnostic and the source code
line because they're different. For '#warning "xxx"' they're the same so
there's no point to showing both and there is a downside that the output is
redundant and confusing.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
  2020-11-27  0:03 ` [Bug preprocessor/98021] " pinskia at gcc dot gnu.org
  2020-11-27  2:14 ` eggert at cs dot ucla.edu
@ 2020-11-27  5:34 ` egallager at gcc dot gnu.org
  2020-11-27  7:36 ` rguenth at gcc dot gnu.org
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: egallager at gcc dot gnu.org @ 2020-11-27  5:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egallager at gcc dot gnu.org
           Keywords|                            |diagnostic

--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
I think there is another bug open about this, but I can't seem to find it right
now...

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (2 preceding siblings ...)
  2020-11-27  5:34 ` egallager at gcc dot gnu.org
@ 2020-11-27  7:36 ` rguenth at gcc dot gnu.org
  2020-11-27 11:18 ` schwab@linux-m68k.org
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-11-27  7:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-11-27
                 CC|                            |dmalcolm at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (3 preceding siblings ...)
  2020-11-27  7:36 ` rguenth at gcc dot gnu.org
@ 2020-11-27 11:18 ` schwab@linux-m68k.org
  2020-11-27 11:54 ` schwab@linux-m68k.org
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-27 11:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> ---
> For '#warning "xxx"' they're the same

That is not true.  There can be comments.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (4 preceding siblings ...)
  2020-11-27 11:18 ` schwab@linux-m68k.org
@ 2020-11-27 11:54 ` schwab@linux-m68k.org
  2020-11-28  1:30 ` eggert at cs dot ucla.edu
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-27 11:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #6 from Andreas Schwab <schwab@linux-m68k.org> ---
Also, the source may come from a different place than the directive.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (5 preceding siblings ...)
  2020-11-27 11:54 ` schwab@linux-m68k.org
@ 2020-11-28  1:30 ` eggert at cs dot ucla.edu
  2020-11-28  8:11 ` schwab@linux-m68k.org
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-11-28  1:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #7 from eggert at cs dot ucla.edu ---
(In reply to Andreas Schwab from comment #5 and #6)
> There can be comments....
> Also, the source may come from a different place than the directive.

For the unusual case where the #warning line invokes preprocessor macros
defined elsewhere, it would be OK to output the warning both before and after
preprocessing (to help with debugging the warning machinery, presumably).
(Comments might cause something similar, I suppose, though that's less
important.)

However, for the case that I mentioned where the #warning line just contains a
string, the duplicate messages are confusing and redundant, and the duplication
should be avoided in this more-typical case.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (6 preceding siblings ...)
  2020-11-28  1:30 ` eggert at cs dot ucla.edu
@ 2020-11-28  8:11 ` schwab@linux-m68k.org
  2020-11-28 17:28 ` eggert at cs dot ucla.edu
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-28  8:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #8 from Andreas Schwab <schwab@linux-m68k.org> ---
That still doesn't handle the case when the source comes from a different
place.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (7 preceding siblings ...)
  2020-11-28  8:11 ` schwab@linux-m68k.org
@ 2020-11-28 17:28 ` eggert at cs dot ucla.edu
  2020-11-28 17:52 ` schwab@linux-m68k.org
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-11-28 17:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #9 from eggert at cs dot ucla.edu ---
(In reply to Andreas Schwab from comment #8)
> That still doesn't handle the case when the source comes from a different
> place.

I don't know what you mean by "source comes from a different place". However,
whatever that situation is, surely GCC could detect it and behave as it does
now, even while it handles the typical case more nicely as I've been
suggesting.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (8 preceding siblings ...)
  2020-11-28 17:28 ` eggert at cs dot ucla.edu
@ 2020-11-28 17:52 ` schwab@linux-m68k.org
  2020-11-28 18:54 ` eggert at cs dot ucla.edu
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-28 17:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #10 from Andreas Schwab <schwab@linux-m68k.org> ---
See the #line directive.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (9 preceding siblings ...)
  2020-11-28 17:52 ` schwab@linux-m68k.org
@ 2020-11-28 18:54 ` eggert at cs dot ucla.edu
  2020-11-28 19:45 ` schwab@linux-m68k.org
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-11-28 18:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #11 from eggert at cs dot ucla.edu ---
(In reply to Andreas Schwab from comment #10)
> See the #line directive.

GCC already treats that case differently, and it can continue to do so.

Come to think of it, GCC works better with #line than it does without. GCC
should treat the ordinary case more like it already treats the #line case,
except that GCC shouldn't say "warning" twice of course (it sounds like an old
episode of "Lost in Space" :-).

::::::::::::::
foo.c
::::::::::::::
#include "bar.h"
::::::::::::::
bar.h
::::::::::::::
#warning "You are too close to the curb"
#line 100 "baz.h"
#warning "Tomorrow is the deadline for paying taxes"


$ gcc -S foo.c
In file included from foo.c:1:
bar.h:1:2: warning: #warning "You are too close to the curb" [-Wcpp]
    1 | #warning "You are too close to the curb"
      |  ^~~~~~~
In file included from foo.c:1:
baz.h:100:2: warning: #warning "Tomorrow is the deadline for paying taxes"
[-Wcpp]

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (10 preceding siblings ...)
  2020-11-28 18:54 ` eggert at cs dot ucla.edu
@ 2020-11-28 19:45 ` schwab@linux-m68k.org
  2020-11-28 20:29 ` eggert at cs dot ucla.edu
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-28 19:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #12 from Andreas Schwab <schwab@linux-m68k.org> ---
> GCC already treats that case differently

In which way?

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (11 preceding siblings ...)
  2020-11-28 19:45 ` schwab@linux-m68k.org
@ 2020-11-28 20:29 ` eggert at cs dot ucla.edu
  2020-11-28 21:06 ` schwab@linux-m68k.org
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-11-28 20:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #13 from eggert at cs dot ucla.edu ---
(In reply to Andreas Schwab from comment #12)
> > GCC already treats that case differently
> 
> In which way?

A "#line" directive suppresses most of the duplication in later #warning
diagnostics, as illustrated in my previous comment.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (12 preceding siblings ...)
  2020-11-28 20:29 ` eggert at cs dot ucla.edu
@ 2020-11-28 21:06 ` schwab@linux-m68k.org
  2020-11-29  1:23 ` eggert at cs dot ucla.edu
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-28 21:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #14 from Andreas Schwab <schwab@linux-m68k.org> ---
I don't follow.  It works exactly the same way.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (13 preceding siblings ...)
  2020-11-28 21:06 ` schwab@linux-m68k.org
@ 2020-11-29  1:23 ` eggert at cs dot ucla.edu
  2020-11-29  8:09 ` schwab@linux-m68k.org
  2021-02-10 20:37 ` dmalcolm at gcc dot gnu.org
  16 siblings, 0 replies; 18+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-11-29  1:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #15 from eggert at cs dot ucla.edu ---
(In reply to Andreas Schwab from comment #14)
> I don't follow.  It works exactly the same way.

Let me try to explain further. In my comment #11, the first directive:

#warning "You are too close to the curb"

generates this diagnostic:

In file included from foo.c:1:
bar.h:1:2: warning: #warning "You are too close to the curb" [-Wcpp]
    1 | #warning "You are too close to the curb"
      |  ^~~~~~~

which contains "You are too close to the curb" twice. In contrast, the second
directive

#warning "Tomorrow is the deadline for paying taxes"

generates only this diagnostic:

In file included from foo.c:1:
baz.h:100:2: warning: #warning "Tomorrow is the deadline for paying taxes"
[-Wcpp]

and this contains "Tomorrow is the deadline for paying taxes" only once, which
is the win I'm suggesting. GCC treats the two #warning directives differently,
and does so because of the intervening #line directive.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (14 preceding siblings ...)
  2020-11-29  1:23 ` eggert at cs dot ucla.edu
@ 2020-11-29  8:09 ` schwab@linux-m68k.org
  2021-02-10 20:37 ` dmalcolm at gcc dot gnu.org
  16 siblings, 0 replies; 18+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-29  8:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #16 from Andreas Schwab <schwab@linux-m68k.org> ---
There is no difference between these cases.  GCC will always show the source
lines that are available.  Of course, it will never pull anything out of thin
air, but that is obvious.

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

* [Bug preprocessor/98021] #warning issues redundant diagnostic lines
  2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
                   ` (15 preceding siblings ...)
  2020-11-29  8:09 ` schwab@linux-m68k.org
@ 2021-02-10 20:37 ` dmalcolm at gcc dot gnu.org
  16 siblings, 0 replies; 18+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2021-02-10 20:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98021

--- Comment #17 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
One aspect of the original case in comment #0 that hasn't been mentioned in
this discussion is that the two #warning messages are related to each other. 
It looks to me like the author of those lines intended for them to emit a block
of related text, but the source-printing gets in the way of this and makes the
connection between the two messages less clear.  I'm not sure what the best
approach here is though.

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

end of thread, other threads:[~2021-02-10 20:37 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 23:53 [Bug preprocessor/98021] New: #warning issues redundant diagnostic lines eggert at cs dot ucla.edu
2020-11-27  0:03 ` [Bug preprocessor/98021] " pinskia at gcc dot gnu.org
2020-11-27  2:14 ` eggert at cs dot ucla.edu
2020-11-27  5:34 ` egallager at gcc dot gnu.org
2020-11-27  7:36 ` rguenth at gcc dot gnu.org
2020-11-27 11:18 ` schwab@linux-m68k.org
2020-11-27 11:54 ` schwab@linux-m68k.org
2020-11-28  1:30 ` eggert at cs dot ucla.edu
2020-11-28  8:11 ` schwab@linux-m68k.org
2020-11-28 17:28 ` eggert at cs dot ucla.edu
2020-11-28 17:52 ` schwab@linux-m68k.org
2020-11-28 18:54 ` eggert at cs dot ucla.edu
2020-11-28 19:45 ` schwab@linux-m68k.org
2020-11-28 20:29 ` eggert at cs dot ucla.edu
2020-11-28 21:06 ` schwab@linux-m68k.org
2020-11-29  1:23 ` eggert at cs dot ucla.edu
2020-11-29  8:09 ` schwab@linux-m68k.org
2021-02-10 20:37 ` dmalcolm at gcc dot gnu.org

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