|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4437" status="New"> |
| 5 | +<title>`constant_of(^^v)` for variable `v` of array type produces reflection of pointer constant</title> |
| 6 | +<section><sref ref="[meta.reflection.queries]"/></section> |
| 7 | +<submitter>Tomasz Kamiński</submitter> |
| 8 | +<date>29 Oct 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +The unintended consequence of the late change of `reflect_constant` to accept its parameter by value |
| 14 | +is that `constant_of(a)` returns a reflection of the value <tt>&a[0]</tt> for a variable of array type. |
| 15 | +<p/> |
| 16 | +For reference, `constant_of` is specified as: |
| 17 | +</p> |
| 18 | +<blockquote><pre> |
| 19 | +if constexpr (is_annotation(<i>R</i>)) { |
| 20 | + return <i>C</i>; |
| 21 | +} else { |
| 22 | + return reflect_constant([: <i>R</i> :]); |
| 23 | +} |
| 24 | +</pre></blockquote> |
| 25 | +<p> |
| 26 | +In case when <tt>[: <i>R</i> :]</tt> is a reference to array, it will decay to a pointer to |
| 27 | +the first element when accepted by value. I believe this is unintended and we should return an |
| 28 | +reflection of an array object instead. |
| 29 | +</p> |
| 30 | +</discussion> |
| 31 | + |
| 32 | +<resolution> |
| 33 | +<p> |
| 34 | +This wording is relative to <paper num="N5014"/>. |
| 35 | +</p> |
| 36 | + |
| 37 | +<ol> |
| 38 | + |
| 39 | +<li><p>Modify <sref ref="[meta.reflection.queries]"/> as indicated:</p> |
| 40 | + |
| 41 | +<blockquote> |
| 42 | +<pre> |
| 43 | +consteval info constant_of(info r); |
| 44 | +</pre> |
| 45 | +<blockquote> |
| 46 | +<p> |
| 47 | +-6 Let <tt><i>R</i></tt> be a constant expression of type `info` such that <tt><i>R</i> == r</tt> is |
| 48 | +`true`. If `r` represents an annotation, then let <tt><i>C</i></tt> be its underlying constant. |
| 49 | +<p/> |
| 50 | +-7- <i>Effects</i>: Equivalent to: |
| 51 | +</p> |
| 52 | +<blockquote><pre> |
| 53 | +if constexpr (is_annotation(<i>R</i>)) { |
| 54 | + return <i>C</i>; |
| 55 | +<ins>} else if constexpr (is_array_type(type_of(<i>R</i>))) { |
| 56 | + return reflect_constant_array([: <i>R</i> :]);</ins> |
| 57 | +} else { |
| 58 | + return reflect_constant([: <i>R</i> :]); |
| 59 | +} |
| 60 | +</pre></blockquote> |
| 61 | +</blockquote> |
| 62 | +</blockquote> |
| 63 | +</li> |
| 64 | +</ol> |
| 65 | + |
| 66 | +</resolution> |
| 67 | + |
| 68 | +</issue> |
0 commit comments