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 ();

Reply via email to