Bug 111230 - show explicit functions in possible candidates
Summary: show explicit functions in possible candidates
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2023-08-29 21:42 UTC by Marek Polacek
Modified: 2024-05-20 16:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-08-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2023-08-29 21:42:32 UTC
struct T {
   T() { } // #1
   explicit T(const T&) { } // #2
};

void
g ()
{
   T t{};
   throw t;
}

shows

h.C: In function ‘void g()’:
h.C:10:10: error: no matching function for call to ‘T::T(T)’
   10 |    throw t;
      |          ^
h.C:2:4: note: candidate: ‘T::T()’
    2 |    T() { } // #1
      |    ^
h.C:2:4: note:   candidate expects 0 arguments, 1 provided
h.C:10:10: note:   in thrown expression
   10 |    throw t;
      |          ^

but it never mentions #2.
Comment 1 Marek Polacek 2023-08-29 21:43:57 UTC
Jason: "in add_candidates when we see an explicit constructor we could add it to bad_fns instead of ignoring it"
Comment 2 Jonathan Wakely 2024-05-20 16:06:27 UTC
Dup of PR 36183?

There Jason said:

We'd probably get that by changing add_candidates to mark an explicit candidate as bad rather than non-viable, and then adding the explanation to convert_like_real.