public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106285] New: Reduce visual noise and confusing grouping when printing overload candidate errors
@ 2022-07-13 20:11 redi at gcc dot gnu.org
  2022-07-13 20:12 ` [Bug c++/106285] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-13 20:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106285
           Summary: Reduce visual noise and confusing grouping when
                    printing overload candidate errors
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

This is the same code as PR 106256:
template<class A, class B>
class C
{
public:
  C() = default;

  template<class AA, class BB>
    C(AA, BB)
    { }

  C(C&&) = default;

private:
  struct __secret_tag  { };
  template<class AA, class BB>
    C(AA&, BB&, __secret_tag)
    { }
};

C<int, int> c({}, {});

We get these errors:

cons.C:20:21: error: no matching function for call to ‘C<int,
int>::C(<brace-enclosed initializer list>, <brace-enclosed initializer list>)’
   20 | C<int, int> c({}, {});
      |                     ^
cons.C:16:5: note: candidate: ‘template<class AA, class BB> C<A, B>::C(AA&,
BB&, __secret_tag) [with BB = AA; A = int; B = int]’
   16 |     C(AA&, BB&, __secret_tag)
      |     ^
cons.C:16:5: note:   template argument deduction/substitution failed:
cons.C:20:21: note:   candidate expects 3 arguments, 2 provided
   20 | C<int, int> c({}, {});
      |                     ^
cons.C:8:5: note: candidate: ‘template<class AA, class BB> C<A, B>::C(AA, BB)
[with BB = AA; A = int; B = int]’
    8 |     C(AA, BB)
      |     ^
cons.C:8:5: note:   template argument deduction/substitution failed:
cons.C:20:21: note:   couldn’t deduce template parameter ‘AA’
   20 | C<int, int> c({}, {});
      |                     ^
cons.C:11:3: note: candidate: ‘constexpr C<A, B>::C(C<A, B>&&) [with A = int; B
= int]’
   11 |   C(C&&) = default;
      |   ^
cons.C:11:3: note:   candidate expects 1 argument, 2 provided
cons.C:5:3: note: candidate: ‘constexpr C<A, B>::C() [with A = int; B = int]’
    5 |   C() = default;
      |   ^
cons.C:5:3: note:   candidate expects 0 arguments, 2 provided



Why do the first and second candidates repeat the caller location:

   20 | C<int, int> c({}, {});
      |                     ^

We've already shown that once with the "no matching function for call to ..."
error at the top. Why are we repeating it? Isn't it just noise that makes the
candidate list harder to read?


Secondly, currently we show the candidate, then its declaration, then the
reason it's not viable:

cons.C:5:3: note: candidate: ‘constexpr C<A, B>::C() [with A = int; B = int]’
    5 |   C() = default;
      |   ^
cons.C:5:3: note:   candidate expects 0 arguments, 2 provided


However, when that's in the middle of a long list of candidates, it's hard to
see where each new candidate begins. The two related notes are separated by the
caret diagnostic.

Would it make more sense to group the reason with the candidate, i.e.:

cons.C:5:3: note: candidate: ‘constexpr C<A, B>::C() [with A = int; B = int]’
cons.C:5:3: note:   candidate expects 0 arguments, 2 provided
    5 |   C() = default;
      |   ^


If we combine these suggestions (remove repeated caret showing call site, and
putting the decl caret after the failure reason, and the PR 106281 ordering
change) I think the result is much better:


cons.C:20:21: error: no matching function for call to ‘C<int,
int>::C(<brace-enclosed initializer list>, <brace-enclosed initializer list>)’
   20 | C<int, int> c({}, {});
      |                     ^
cons.C:8:5: note: candidate: ‘template<class AA, class BB> C<A, B>::C(AA, BB)
[with BB = AA; A = int; B = int]’
cons.C:8:5: note:   template argument deduction/substitution failed:
cons.C:20:21: note:   couldn’t deduce template parameter ‘AA’
    8 |     C(AA, BB)
      |     ^
cons.C:11:3: note: candidate: ‘constexpr C<A, B>::C(C<A, B>&&) [with A = int; B
= int]’
cons.C:11:3: note:   candidate expects 1 argument, 2 provided
   11 |   C(C&&) = default;
      |   ^
cons.C:5:3: note: candidate: ‘constexpr C<A, B>::C() [with A = int; B = int]’
cons.C:5:3: note:   candidate expects 0 arguments, 2 provided
    5 |   C() = default;
      |   ^
cons.C:16:5: note: candidate: ‘template<class AA, class BB> C<A, B>::C(AA&,
BB&, __secret_tag) [with BB = AA; A = int; B = int]’
cons.C:16:5: note:   template argument deduction/substitution failed:
cons.C:20:21: note:   candidate expects 3 arguments, 2 provided
   16 |     C(AA&, BB&, __secret_tag)
      |     ^

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

* [Bug c++/106285] Reduce visual noise and confusing grouping when printing overload candidate errors
  2022-07-13 20:11 [Bug c++/106285] New: Reduce visual noise and confusing grouping when printing overload candidate errors redi at gcc dot gnu.org
@ 2022-07-13 20:12 ` redi at gcc dot gnu.org
  2022-07-13 22:01 ` mpolacek at gcc dot gnu.org
  2022-07-13 22:35 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-13 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=106281

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> This is the same code as PR 106256:

Oops, sorry, that should be PR 106281

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

* [Bug c++/106285] Reduce visual noise and confusing grouping when printing overload candidate errors
  2022-07-13 20:11 [Bug c++/106285] New: Reduce visual noise and confusing grouping when printing overload candidate errors redi at gcc dot gnu.org
  2022-07-13 20:12 ` [Bug c++/106285] " redi at gcc dot gnu.org
@ 2022-07-13 22:01 ` mpolacek at gcc dot gnu.org
  2022-07-13 22:35 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-13 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-07-13

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

* [Bug c++/106285] Reduce visual noise and confusing grouping when printing overload candidate errors
  2022-07-13 20:11 [Bug c++/106285] New: Reduce visual noise and confusing grouping when printing overload candidate errors redi at gcc dot gnu.org
  2022-07-13 20:12 ` [Bug c++/106285] " redi at gcc dot gnu.org
  2022-07-13 22:01 ` mpolacek at gcc dot gnu.org
@ 2022-07-13 22:35 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-13 22:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Re the grouping of related notes, I notice that with -fdiagnostics-format=json
there is no proper structure. All the notes are just children of the error, at
the same level. So the nesting is something like:

error: no matching function for call to ... {
  location of failed call site,
  candidate: decl,
  reason for failure,
  location of decl,
  candidate: decl,
  reason for failure,
  location of decl,
  candidate: decl,
  reason for failure,
  location of decl,
}

Ideally we'd have this nesting:

error: no matching function for call to ... {
  location of failed call site,
  candidate: decl {
    reason for failure,
    location of decl
  },
  candidate: decl {
    reason for failure,
    location of decl
  },
  candidate: decl {
    reason for failure,
    location of decl
  },
}

i.e. the error would have the candidates as direct children, but then the
locations and failure reason for each candidate would be children of the
candidate.

This would allow IDEs to group the info about each candidate and optionally
collapse it. With the current (lack of) structure that's not possible. Every
note is at the same level and there's no indication which ones are related to
each other.

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

end of thread, other threads:[~2022-07-13 22:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 20:11 [Bug c++/106285] New: Reduce visual noise and confusing grouping when printing overload candidate errors redi at gcc dot gnu.org
2022-07-13 20:12 ` [Bug c++/106285] " redi at gcc dot gnu.org
2022-07-13 22:01 ` mpolacek at gcc dot gnu.org
2022-07-13 22:35 ` redi 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).