|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4305" status="New"> |
| 5 | +<title>Missing user requirements on `type_order` template</title> |
| 6 | +<section><sref ref="[compare.type]"/></section> |
| 7 | +<submitter>Daniel Krügler</submitter> |
| 8 | +<date>27 Jul 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +The recently approved paper <paper num="P2830R10"/> proposes to add the new `type_order` |
| 14 | +type traits to <sref ref="[cmp]"/> (and thus outside of <sref ref="[type.traits]"/>), |
| 15 | +which has the subtle and most likely unintended effect, that it doesn't fall under the |
| 16 | +general requirement expressed in <sref ref="[meta.rqmts]"/> p4, |
| 17 | +</p> |
| 18 | +<blockquote><p> |
| 19 | +Unless otherwise specified, the behavior of a program that adds specializations for |
| 20 | +any of the templates specified in <sref ref="[meta.rqmts]"/> is undefined. |
| 21 | +</p></blockquote> |
| 22 | +<p> |
| 23 | +and so in principle the explicit allowance specified in <sref ref="[namespace.std]"/> p2, |
| 24 | +</p> |
| 25 | +<blockquote><p> |
| 26 | +Unless explicitly prohibited, a program may add a template specialization for any standard |
| 27 | +library class template to namespace `std` […] |
| 28 | +</p></blockquote> |
| 29 | +<p> |
| 30 | +holds. So we need to add extra wording to the `type_order` specification in |
| 31 | +<sref ref="[compare.type]"/> to prohibit such program specializations. |
| 32 | +<p/> |
| 33 | +This was reported shortly before the Sofia meeting |
| 34 | +<a href="https://lists.isocpp.org/lib/2025/06/31725.php">during reflector discussion</a> |
| 35 | +but seems to be forgotten before the final paper appeared on plenary. |
| 36 | +<p/> |
| 37 | +During the reflector discussion two possible ways to solve this issue were pointed out: |
| 38 | +</p> |
| 39 | +<ol> |
| 40 | +<li><p>The most simple one would mimic the wording in <sref ref="[meta.rqmts]"/> p4 |
| 41 | +quoted above.</p></li> |
| 42 | +<li><p>Instead of introducing just another undefined opportunity to run into undefined |
| 43 | +behaviour it has been pointed out that we could follow the approach taken by `std::initializer_list` |
| 44 | +and make the program ill-formed in this case, as specified in <sref ref="[initializer.list.syn]"/> p2: |
| 45 | +</p> |
| 46 | +<blockquote><p> |
| 47 | +If an explicit specialization or partial specialization of `initializer_list` is declared, |
| 48 | +the program is ill-formed. |
| 49 | +</p></blockquote> |
| 50 | +</li> |
| 51 | +</ol> |
| 52 | +Jonathan Wakely responded to the reflector discussion: |
| 53 | +<blockquote><p> |
| 54 | +I think ill-formed would be better. It shouldn't be difficult for implementations to have special cases that are disallowed. |
| 55 | +</p></blockquote> |
| 56 | +<p> |
| 57 | +Given the already existing experience with `std::initializer_list` the proposed wording below |
| 58 | +therefore follows the ill-formed program approach. |
| 59 | +</p> |
| 60 | +</discussion> |
| 61 | + |
| 62 | +<resolution> |
| 63 | +<p> |
| 64 | +This wording is relative to this |
| 65 | +<a href="https://github.com/cplusplus/draft/actions/runs/16433597877/artifacts/3583518547">CD preview draft</a>. |
| 66 | +</p> |
| 67 | + |
| 68 | +<ol> |
| 69 | + |
| 70 | +<li><p>Modify <sref ref="[compare.type]"/> as indicated:</p> |
| 71 | + |
| 72 | +<blockquote> |
| 73 | +<pre> |
| 74 | +template<class T, class U> |
| 75 | + struct type_order; |
| 76 | +</pre> |
| 77 | +<blockquote> |
| 78 | +<p> |
| 79 | +-2- The name `type_order` denotes a <i>Cpp17BinaryTypeTrait</i> (<sref ref="[meta.rqmts]"/>) with a base |
| 80 | +characteristic of <tt>integral_constant<strong_ordering, <i>TYPE-ORDER</i>(T, U)></tt>. |
| 81 | +<p/> |
| 82 | +<ins>-?- If an explicit specialization or partial specialization of `type_order` is declared, the program is ill-formed.</ins> |
| 83 | +<p/> |
| 84 | +-3- <i>Recommended practice</i>: The order should be lexicographical on parameter-type-lists and template |
| 85 | +argument lists. |
| 86 | +</p> |
| 87 | +</blockquote> |
| 88 | +</blockquote> |
| 89 | +</li> |
| 90 | + |
| 91 | +</ol> |
| 92 | + |
| 93 | +</resolution> |
| 94 | + |
| 95 | +</issue> |
0 commit comments