[all-commits] [llvm/llvm-project] 340eac: [C++20] Implement P2113R0: Changes to the Partial ...

Yuanfang Chen via All-commits all-commits at lists.llvm.org
Tue Oct 18 11:59:30 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 340eac01f7dad6c24cee35dd35f2484098dd6b1a
      https://github.com/llvm/llvm-project/commit/340eac01f7dad6c24cee35dd35f2484098dd6b1a
  Author: Yuanfang Chen <yuanfang.chen at sony.com>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/AST/DeclTemplate.h
    M clang/include/clang/Sema/Sema.h
    M clang/lib/AST/DeclTemplate.cpp
    M clang/lib/Sema/SemaConcept.cpp
    M clang/lib/Sema/SemaOverload.cpp
    M clang/lib/Sema/SemaTemplate.cpp
    M clang/lib/Sema/SemaTemplateDeduction.cpp
    M clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
    M clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
    M clang/www/cxx_status.html

  Log Message:
  -----------
  [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

This implementation matches GCC behavior in that [[ https://eel.is/c++draft/temp.func.order#6.2.1 | temp.func.order p6.2.1 ]] is not implemented [1]. I reached out to the GCC author to confirm that some changes elsewhere to overload resolution are probably needed, but no solution has been developed sufficiently [3].

Most of the wordings are implemented straightforwardly. However,
for [[ https://eel.is/c++draft/temp.func.order#6.2.2 | temp.func.order p6.2.2 ]] "... or if the function parameters that positionally correspond between the two templates are not of the same type", the "same type" is not very clear ([2] is a bug related to this). Here is a quick example
```
template <C T, C U>        int f(T, U);
template <typename T, C U> int f(U, T);

int x = f(0, 0);
```
Is the `U` and `T` from different `f`s the "same type"? The answer is NO even though both `U` and `T` are deduced to be `int` in this case. The reason is that `U` and `T` are dependent types, according to [[ https://eel.is/c++draft/temp.over.link#3 |  temp.over.link p3 ]], they can not be the "same type".

To check if two function parameters are the "same type":
* For //function template//: compare the function parameter canonical types and return type between two function templates.
* For //class template/partial specialization//: by [[ https://eel.is/c++draft/temp.spec.partial.order#1.2 | temp.spec.partial.order p1.2 ]], compare the injected template arguments between two templates using hashing(TemplateArgument::Profile) is enough.

[1] https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=57b4daf8dc4ed7b669cc70638866ddb00f5b7746
[2] https://github.com/llvm/llvm-project/issues/49308
[3] https://lists.isocpp.org/core/2020/06/index.php#msg9392

Fixes https://github.com/llvm/llvm-project/issues/54039
Fixes https://github.com/llvm/llvm-project/issues/49308 (PR49964)

Reviewed By: royjacobson, #clang-language-wg, mizvekov

Differential Revision: https://reviews.llvm.org/D128750




More information about the All-commits mailing list