[Clang] Don't consider default constructors ineligible if the more constrained constr...
authorRoy Jacobson <roi.jacobson1@gmail.com>
Sun, 4 Dec 2022 19:02:57 +0000 (21:02 +0200)
committerRoy Jacobson <roi.jacobson1@gmail.com>
Mon, 5 Dec 2022 21:02:37 +0000 (23:02 +0200)
commit7d58c95635cce63ce6acd43c953b57f10bf5c686
tree4ca91b6be9c18496c119deb890db0b156496421a
parent7fe4abbbc2702c09303110a3f4cd9f97494bc887
[Clang] Don't consider default constructors ineligible if the more constrained constructor is a template

Partially solves https://github.com/llvm/llvm-project/issues/59206:

We now mark trivial constructors as eligible even if there's a more constrained templated default constructor. Although technically non-conformant, this solves problems with pretty reasonable uses cases like
```
template<int n>
struct Foo {
constexpr Foo() = default;

template<class... Ts>
Foo(Ts... vals) requires(sizeof...(Ts) == n) {}
};
```
where we currently consider the default constructor to be ineligible and therefor inheriting/containing classes have non trivial constructors. This is aligned with GCC: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=c75ebe76ae12ac4020f20a24f34606a594a40d15

This doesn't change `__is_trivial`. Although we're technically standard conformant in this regard, GCC/MSVC exhibit different behaviors that seem to make more sense. An issue has been filed to CWG and we await their response.

Reviewed By: erichkeane, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D139038
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp