File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =' 1.0' encoding =' utf-8' standalone =' no' ?>
2
+ <!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3
+
4
+ <issue num =" 4148" status =" New" >
5
+ <title ><code >unique_ptr::operator*</code > should not allow dangling references</title >
6
+ <section ><sref ref =" [unique.ptr.single.observers]" /></section >
7
+ <submitter >Jonathan Wakely</submitter >
8
+ <date >02 Sep 2024</date >
9
+ <priority >99</priority >
10
+
11
+ <discussion >
12
+ <p >
13
+ If <code >unique_ptr< T,D> ::element_type*</code > and <code >D::pointer</code >
14
+ are not the same type, it's possible for `operator*()` to return a dangling
15
+ reference that has undefined behaviour.
16
+ </p >
17
+ <pre ><code >
18
+ struct deleter {
19
+ using pointer = long*;
20
+ void operator()(pointer) const {}
21
+ };
22
+ long l = 0;
23
+ std::unique_ptr< const int, deleter> p(& l);
24
+ int i = *p; <i ><strong >// undefined</strong ></i >
25
+ </code ></pre >
26
+ <p >
27
+ We should make this case ill-formed.
28
+ </p >
29
+ </discussion >
30
+
31
+ <resolution >
32
+ <p >
33
+ This wording is relative to <paper num =" N4988" />.
34
+ </p >
35
+ <ol >
36
+ <li ><p >Modify <sref ref =" [unique.ptr.single.observers]" /> as indicated:</p >
37
+ <blockquote >
38
+ <pre >
39
+ constexpr add_lvalue_reference_t< T> operator*() const noexcept(noexcept(*declval< pointer> ()));
40
+ </pre >
41
+ <blockquote >
42
+ <p >
43
+ <ins >-?- <i >Mandates</i >:
44
+ <code >reference_converts_from_temporary_v< add_lvalue_reference_t< T> ,
45
+ decltype(*declval< pointer> ())> </code >
46
+ is `false`.
47
+ </ins >
48
+ </p >
49
+ <p >
50
+ -1- <i >Preconditions</i >: `get() != nullptr` <ins >is `true`</ins >.
51
+ </p >
52
+ <p >
53
+ -2- <i >Returns</i >: `*get()`.
54
+ </p >
55
+ </blockquote >
56
+ </blockquote >
57
+ </li >
58
+ </ol >
59
+ </resolution >
60
+
61
+ </issue >
You can’t perform that action at this time.
0 commit comments