public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96310] New: Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note
@ 2020-07-24 15:36 romain.geissler at amadeus dot com
  2020-07-25 20:10 ` [Bug c++/96310] " msebor at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: romain.geissler at amadeus dot com @ 2020-07-24 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96310
           Summary: Ignoring Wnonnull via pragma gcc diagnostics still
                    produces a unwanted note
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Hi,

When trying to ignore some uses of null object which apparently are done on
purpose in Boost::concept, I noticed that ignoring the Wnonnull warning via
pragmas still produces an unwanted note giving the details of the callstack.

See this (compiled with -Wnonnull):

struct C {
    void method() {}
};

void f()
{
#pragma GCC diagnostic push                                                     
#pragma GCC diagnostic ignored "-Wnonnull" 
    static_cast<C*>(0)->method();
#pragma GCC diagnostic pop
}

generates the following compiler note output, while we did expect none:

<source>: In function 'void f()':
<source>:2:10: note: in a call to non-static member function 'void C::method()'
    2 |     void method() {}
      |          ^~~~~~
Compiler returned: 0

Cheers,
Romain

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

* [Bug c++/96310] Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note
  2020-07-24 15:36 [Bug c++/96310] New: Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note romain.geissler at amadeus dot com
@ 2020-07-25 20:10 ` msebor at gcc dot gnu.org
  2020-07-25 20:24 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-07-25 20:10 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2020-07-25
     Ever confirmed|0                           |1
   Target Milestone|---                         |11.0
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org

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

* [Bug c++/96310] Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note
  2020-07-24 15:36 [Bug c++/96310] New: Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note romain.geissler at amadeus dot com
  2020-07-25 20:10 ` [Bug c++/96310] " msebor at gcc dot gnu.org
@ 2020-07-25 20:24 ` cvs-commit at gcc dot gnu.org
  2020-07-25 20:25 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-25 20:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:e0633768a1a2efe689e5505b3a95aa949d704b06

commit r11-2322-ge0633768a1a2efe689e5505b3a95aa949d704b06
Author: Martin Sebor <msebor@redhat.com>
Date:   Sat Jul 25 14:21:47 2020 -0600

    Fix PR c++/96310 - Ignoring -Wnonnull via pragma gcc diagnostics still
produces an unwanted note.

    gcc/c-family/ChangeLog:
            PR c++/96310
            * c-common.c (check_nonnull_arg): Print note only when warning was
            issued.

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

* [Bug c++/96310] Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note
  2020-07-24 15:36 [Bug c++/96310] New: Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note romain.geissler at amadeus dot com
  2020-07-25 20:10 ` [Bug c++/96310] " msebor at gcc dot gnu.org
  2020-07-25 20:24 ` cvs-commit at gcc dot gnu.org
@ 2020-07-25 20:25 ` msebor at gcc dot gnu.org
  2020-07-29  2:23 ` egallager at gcc dot gnu.org
  2020-07-29 16:47 ` msebor at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-07-25 20:25 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
             Blocks|                            |95507

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in r11-2322.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95507
[Bug 95507] [meta-bug] bogus/missing -Wnonnull

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

* [Bug c++/96310] Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note
  2020-07-24 15:36 [Bug c++/96310] New: Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note romain.geissler at amadeus dot com
                   ` (2 preceding siblings ...)
  2020-07-25 20:25 ` msebor at gcc dot gnu.org
@ 2020-07-29  2:23 ` egallager at gcc dot gnu.org
  2020-07-29 16:47 ` msebor at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: egallager at gcc dot gnu.org @ 2020-07-29  2:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
These types of bugs seem kind of common; I keep thinking there should be some
way of automatically checking that call to inform() only come after warning()
or warning_at() if their return values got checked... I was thinking adding
__attribute__((warn_unused_result)) on warning() and warning_at() at first, but
that would also trigger in cases in which there's no following inform() call,
in which it's ok to ignore the return value... maybe some magic could happen
via David Malcolm's auto_diagnostic_group class?

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

* [Bug c++/96310] Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note
  2020-07-24 15:36 [Bug c++/96310] New: Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note romain.geissler at amadeus dot com
                   ` (3 preceding siblings ...)
  2020-07-29  2:23 ` egallager at gcc dot gnu.org
@ 2020-07-29 16:47 ` msebor at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-07-29 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
I've been thinking about that too but not really coming up with anything given
the current design.  One idea is to change warning() to return a unique "token"
and have inform() take it as an argument and do its thing based on its value. 
The code would then go back to the original:

    warntok = warning_at (loc, OPT_Wnonnull,
                          "%qs pointer null", "this");
    if (pctx->fndecl)
        inform (warntok,
                DECL_SOURCE_LOCATION (pctx->fndecl),
                "in a call to non-static member function %qD",
                pctx->fndecl);

A more object-oriented alternative is to extend the auto_diagnostic_group class
to create a series of related messages, starting with an error or warning, and
followed by any number of notes, and have it either issue all of them or none
in a single call.  That might look like this:

  auto_diagnostic_group adg;
  adg.warning_at (loc, OPT_Wnonnull,
                  "%qs pointer null", "this");
  if (pctx->fndecl)
      adg.inform (DECL_SOURCE_LOCATION (pctx->fndecl),
                  "in a call to non-static member function %qD",
                  pctx->fndecl);
  adg.do_it ();

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

end of thread, other threads:[~2020-07-29 16:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 15:36 [Bug c++/96310] New: Ignoring Wnonnull via pragma gcc diagnostics still produces a unwanted note romain.geissler at amadeus dot com
2020-07-25 20:10 ` [Bug c++/96310] " msebor at gcc dot gnu.org
2020-07-25 20:24 ` cvs-commit at gcc dot gnu.org
2020-07-25 20:25 ` msebor at gcc dot gnu.org
2020-07-29  2:23 ` egallager at gcc dot gnu.org
2020-07-29 16:47 ` msebor 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).