Page MenuHomePhabricator

[Clang] Don't consider default constructors ineligible if the more constrained constructor is a template
ClosedPublic

Authored by royjacobson on Nov 30 2022, 11:46 AM.

Details

Summary

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.

Diff Detail

Event Timeline

royjacobson created this revision.Nov 30 2022, 11:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 30 2022, 11:46 AM

Update so this doesn't change type triviality.

royjacobson published this revision for review.Dec 4 2022, 11:13 AM
royjacobson retitled this revision from Draft fix for 59206 to [Clang] Don't consider default constructors ineligible if the more constrained constructor is a template.
royjacobson edited the summary of this revision. (Show Details)
royjacobson added reviewers: erichkeane, Restricted Project, hubert.reinterpretcast.
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2022, 11:13 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
erichkeane accepted this revision.Dec 5 2022, 6:55 AM
This revision is now accepted and ready to land.Dec 5 2022, 6:55 AM
This revision was landed with ongoing or failed builds.Dec 5 2022, 1:02 PM
This revision was automatically updated to reflect the committed changes.