Skip to content

Change T.46 to not require copyability, and to account for traits types (see #2281)#2320

Open
hsutter wants to merge 1 commit intomasterfrom
Update-T.46
Open

Change T.46 to not require copyability, and to account for traits types (see #2281)#2320
hsutter wants to merge 1 commit intomasterfrom
Update-T.46

Conversation

@hsutter
Copy link
Contributor

@hsutter hsutter commented Mar 5, 2026

Closes #2281

##### Exceptions

Semiregular requires default constructible.
A trait type is not necessarily movable and default-constructible. Templates that use trait types usually use them with `Trait::something` scope resolution syntax, rather than using objects of the trait type.
Copy link
Contributor

@jwakely jwakely Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trait type is not necessarily movable and default-constructible.

I don't think this is true, all standard trait types are movable and default constructible, and you probably want them to be so that you can use them for tag dispatching.

Templates that use trait types usually use them with Trait::something scope resolution syntax, rather than using objects of the trait type.

OK, this is true, but irrelevant.

I don't think the issue is saying that trait types themselves are not movable and therefore we need an exception for trait types. I think it's saying that using non-movable types as the template arguments of traits violates the guideline. But of course we want to be able to use std::is_move_assignable_v<X> and is_default_constructible_v<X> even if X is not movable or not default constructible.

So I think this change misses the mark.

I think if you want to keep the rule then you should do something like make an exception for templates which do not actually construct the type, e.g. type traits which are purely compile-time queries for properties of a type and do not have any side effects.

The case of unique_ptr<X> requires a different exception. That certainly does do things with an object of type X but there is no reason whatsoever that it needs X to be semiregular. It never makes a new object of type X, and using unique_ptr to manage non-movable objects on the heap is a perfectly valid thing to do.

##### Enforcement

* Flag types used as template arguments that are not at least semiregular.
* Flag types used as template arguments that do not satisfy both `std::movable` and `std::default_constructible` and that are using in the template without `::` scope resolution syntax.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "that are used" not "that are using", but I think the change just needs to be rewritten anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

T.46 contradicts the idea of type traits and is not resource-friendly

2 participants