[all-commits] [llvm/llvm-project] 3b639d: [Clang] Clarify diagnostic notes for implicitly ge...

Younan Zhang via All-commits all-commits at lists.llvm.org
Tue Jul 2 04:35:09 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3b639d7d1d9b9f352c57460deaf70aaad238f8d9
      https://github.com/llvm/llvm-project/commit/3b639d7d1d9b9f352c57460deaf70aaad238f8d9
  Author: Younan Zhang <zyn7109 at gmail.com>
  Date:   2024-07-02 (Tue, 02 Jul 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Sema/SemaOverload.cpp
    M clang/test/CXX/drs/cwg26xx.cpp
    M clang/test/CXX/expr/expr.post/expr.type.conv/p1.cpp
    M clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
    M clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp
    M clang/test/Modules/template_name_lookup.cpp
    M clang/test/PCH/cxx-explicit-specifier.cpp
    M clang/test/Sema/tls_alignment.cpp
    M clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
    M clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
    M clang/test/SemaCXX/cxx2a-explicit-bool.cpp
    M clang/test/SemaCXX/gh65522.cpp
    M clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
    M clang/test/SemaCXX/lookup-template-name-extern-CXX.cpp
    M clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
    M clang/test/SemaTemplate/class-template-id.cpp
    M clang/test/SemaTemplate/ctad.cpp
    M clang/test/SemaTemplate/deduction-crash.cpp
    M clang/test/SemaTemplate/deduction-guide.cpp
    M clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
    M clang/test/SemaTemplate/temp_arg.cpp

  Log Message:
  -----------
  [Clang] Clarify diagnostic notes for implicitly generated deduction guides (#96084)

Given the following invalid code,
```cpp
template <class T>
struct S {
  T *a;
};
S s = {1};
```
we produce such diagnostics currently:
```
<source>:2:8: note: candidate template ignored: could not match 'S<T>' against 'int'
    2 | struct S {
      |        ^
<source>:2:8: note: candidate template ignored: could not match 'T *' against 'int'
```
Which I think is confusing because there's no `S<T>` nor `T *` at the
location it points to. This is because we're deducing the initializer
against implicitly generated deduction guides, and their source
locations just point to the corresponding `RecordDecl`. Hence the
misleading notes.

This patch alleviates the issue by adding extra notes demonstrating
which implicit deduction guide we're deducing against. In other words,
in addition to the note of `could not match 'T *' against 'int'`, we
would also say the implicit deduction guide we're trying to use:
`template <class T> S(T *) -> S<T>`, which looks clearer IMO.

---------

Co-authored-by: Sirraide <aeternalmail at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list