Skip to content

Commit 9595eb1

Browse files
authored
[libc++][test] Close LWG3018 and add tests (#93047)
1 parent 2655897 commit 9595eb1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

libcxx/docs/Status/Cxx20Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
"","","","","",""
192192
"`1203 <https://wg21.link/LWG1203>`__","More useful rvalue stream insertion","Prague","|Complete|","12.0"
193193
"`2859 <https://wg21.link/LWG2859>`__","Definition of *reachable* in [ptr.launder] misses pointer arithmetic from pointer-interconvertible object","Prague","",""
194-
"`3018 <https://wg21.link/LWG3018>`__","``shared_ptr``\ of function type","Prague","",""
194+
"`3018 <https://wg21.link/LWG3018>`__","``shared_ptr``\ of function type","Prague","|Nothing To Do|",""
195195
"`3050 <https://wg21.link/LWG3050>`__","Conversion specification problem in ``chrono::duration``\ constructor","Prague","|Complete|","19.0","|chrono|"
196196
"`3141 <https://wg21.link/LWG3141>`__","``CopyConstructible``\ doesn't preserve source values","Prague","|Nothing to do|",""
197197
"`3150 <https://wg21.link/LWG3150>`__","``UniformRandomBitGenerator``\ should validate ``min``\ and ``max``\ ","Prague","|Complete|","13.0","|ranges|"

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int*, bad_deleter>
4848
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int(*)[5], test_deleter<int> >::value, "");
4949
#endif
5050

51+
int f() { return 5; }
52+
53+
// https://cplusplus.github.io/LWG/issue3018
54+
// LWG 3018. shared_ptr of function type
55+
struct function_pointer_deleter {
56+
function_pointer_deleter(bool& deleter_called) : deleter_called_(deleter_called) {}
57+
58+
void operator()(int (*)()) const { deleter_called_ = true; }
59+
60+
bool& deleter_called_;
61+
};
62+
63+
void test_function_type() {
64+
bool deleter_called = false;
65+
{
66+
std::shared_ptr<int()> p(&f, function_pointer_deleter(deleter_called));
67+
assert((*p)() == 5);
68+
}
69+
assert(deleter_called);
70+
}
71+
5172
int main(int, char**)
5273
{
5374
{
@@ -94,5 +115,6 @@ int main(int, char**)
94115
}
95116
#endif // TEST_STD_VER >= 11
96117

118+
test_function_type();
97119
return 0;
98120
}

0 commit comments

Comments
 (0)