[clang] [Clang] Clarify diagnostic notes for implicitly generated deduction guides (PR #96084)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 20 04:49:05 PDT 2024


zyn0217 wrote:

> C++ error messages already have a reputation of being rather long; I’m candidly doubtful as to whether this would help most users too much...

I think this is more about making us more accurate when we want to point out there's something wrong with users' code. Admittedly, it's hard to tell whether most users would gain much from the diagnostic notes, and I could also bet that in most cases, people tend to evade a flood of errors and their accompanying notes.

It is usually the case that a bunch of notes might bury the most helpful error message indicating where the first error happens; however, I don't think this would exacerbate it much because this 1) only notes implicitly generated CTAD guides; 2) won't be chatty if the guide is generated over a user-defined constructor: we have already pointed to a feasible source location that makes things clear.

> Perhaps an approach more similar to what we display for ambiguous cast paths would be better i.e. list each implicit deduction guide we tried in a single note

Thanks for suggesting a better approach. However, doing so would require big surgery in our diagnostic building logic for overloads. We don't explain the reason for deduction failure in an error; instead, we do so in the following notes. To be clear, we now have ~16 deduction failure kinds, each with its own diagnostic message. Given that, I don't think it's necessary (and probably undoable) to special case the CTAD guides for each note...

It's also sad that we're unable to pretty-print the deduction guides in a diagnostic. If I read it correctly, we currently only support printing either1) a verbatim code snippet or 2) a FIXIT suggestion. And neither does work for this case, though.


https://github.com/llvm/llvm-project/pull/96084


More information about the cfe-commits mailing list