File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
tests/std/tests/P2278R4_basic_const_iterator Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -2211,6 +2211,9 @@ struct _Basic_const_iterator_category<_Iter> {
22112211_EXPORT_STD template <input_iterator _Iter>
22122212class basic_const_iterator : public _Basic_const_iterator_category<_Iter> {
22132213private:
2214+ template <input_iterator>
2215+ friend class basic_const_iterator;
2216+
22142217 /* [[no_unique_address]] */ _Iter _Current{};
22152218
22162219 using _Reference = iter_const_reference_t<_Iter>;
Original file line number Diff line number Diff line change @@ -374,9 +374,35 @@ constexpr void test_p2836r1() {
374374 }
375375}
376376
377+ // GH-5321 "<xutility>: basic_const_iterator<int *> Cannot Convert to basic_const_iterator<const int *>"
378+ constexpr void test_conversion_instantiation () {
379+ struct Base {};
380+ struct Derived : Base {};
381+
382+ {
383+ basic_const_iterator<const int *> cit = basic_const_iterator<int *>{};
384+ assert (cit.base () == nullptr );
385+ }
386+ {
387+ int n{};
388+ basic_const_iterator<const int *> cit = basic_const_iterator<int *>{&n};
389+ assert (cit.base () == &n);
390+ }
391+ {
392+ basic_const_iterator<Base*> cit = basic_const_iterator<Derived*>{};
393+ assert (cit.base () == nullptr );
394+ }
395+ {
396+ Derived d{};
397+ basic_const_iterator<Base*> cit = basic_const_iterator<Derived*>{&d};
398+ assert (cit.base () == static_cast <Base*>(&d));
399+ }
400+ }
401+
377402constexpr bool all_tests () {
378403 instantiation_test ();
379404 test_p2836r1 ();
405+ test_conversion_instantiation ();
380406 return true ;
381407}
382408
You can’t perform that action at this time.
0 commit comments