|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4306" status="New"> |
| 5 | +<title>Interaction between LWG 2259 and <i>Constraints</i> of member functions</title> |
| 6 | +<section><sref ref="[member.functions]"/></section> |
| 7 | +<submitter>Jiang An</submitter> |
| 8 | +<date>24 Jul 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +<sref ref="[member.functions]"/>/2 seems to allow that even when the constraints are not met, |
| 14 | +such a default constructor can be selected, because no restriction is imposed when no overload |
| 15 | +is originally selected. Per the discussion in LWG <iref ref="2563"/> (closed as NAD), it even |
| 16 | +seems to allow the implementation to add a default constructor when there's originally none. |
| 17 | +<p/> |
| 18 | +However, we're constraining some member functions, e.g. default constructors of `unique_ptr`, |
| 19 | +`tuple`, and `variant`. Allowance of more permissive overload sets of constructors effectively |
| 20 | +renders the <i>Constraints</i> meaningless, because even if the implementation doesn't constrain |
| 21 | +the default constructors at all, it can still satisfy the restriction in |
| 22 | +<sref ref="[member.functions]"/>/2 since LWG <iref ref="2259"/>. |
| 23 | +<p/> |
| 24 | +Consider the following example: |
| 25 | +</p> |
| 26 | +<blockquote><pre> |
| 27 | +struct S |
| 28 | +{ |
| 29 | + S() = delete; |
| 30 | +}; |
| 31 | + |
| 32 | +static_assert(std::is_default_constructible_v<std::tuple<S>>); |
| 33 | +std::tuple<S> t; |
| 34 | +</pre></blockquote> |
| 35 | +<p> |
| 36 | +Even though currently the default constructor of `std::tuple` is constrained (<sref ref="[tuple.cnstr]"/>/6), |
| 37 | +<sref ref="[member.functions]"/>/2 seemingly allows the implementation to add another overload that's also |
| 38 | +a default constructor, constrained by "<tt>is_default_constructible_v<T<sub><i>i</i></sub>></tt> is `false` |
| 39 | +for at least one <tt><i>i</i></tt>", and then render the example well-formed or only error on actual |
| 40 | +instantiation of the "additional" default constructor. Note that such an additional overload effectively |
| 41 | +removes the <i>Constraints</i> element requirements. |
| 42 | +<p/> |
| 43 | +As shown by the example, the allowance in <sref ref="[member.functions]"/>/2 can weaken or even invalidate |
| 44 | +<i>Constraints</i> of member functions. |
| 45 | +<p/> |
| 46 | +So perhaps some wording change is necessary to guarantee the <i>Constraints</i> of member functions to be meaningful. |
| 47 | +</p> |
| 48 | +</discussion> |
| 49 | + |
| 50 | +<resolution> |
| 51 | +</resolution> |
| 52 | + |
| 53 | +</issue> |
0 commit comments