Change T.46 to not require copyability, and to account for traits types (see #2281)#2320
Change T.46 to not require copyability, and to account for traits types (see #2281)#2320
Conversation
| ##### 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. |
There was a problem hiding this comment.
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::somethingscope 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. |
There was a problem hiding this comment.
Should be "that are used" not "that are using", but I think the change just needs to be rewritten anyway.
Closes #2281