constant_iterator and counting_iterator dereference attempts to bind a const object to a reference
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với include/boost/compute/iterator/constant_iterator.hpp, đặc biệt là constant_iterator_base và dereference(), sau đó kiểm tra test/test_constant_iterator.cpp. Thực hiện dereference trực tiếp của constant_iterator và trường hợp counting_iterator tương ứng bằng trình biên dịch Intel oneAPI; được xem là hoàn tất khi các trường hợp này biên dịch được và các bài kiểm tra iterator đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The following test case illustrates a compilation failure that occurs when attempting to dereference an instance of constant_iterator instantiated for a non-const value type.
#include <boost/compute/iterator/constant_iterator.hpp>
using namespace boost::compute;
int f(constant_iterator<int> ci) {
return *ci;
}
When compiled by the Intel oneAPI compiler (a fork of Clang), the following error (demonstrated using the oneAPI icx driver on Windows) is produced:
$ icx /c /I../tmp/boost_1_90_0 /EHsc -std:c++20 t.cpp
...
In file included from ...\t.cpp:1:
...\boost_1_90_0\boost\compute\iterator\constant_iterator.hpp(113,16): error:
binding reference of type 'int' to value of type 'const int' drops 'const' qualifier
113 | return m_value;
| ^~~~~~~
...\boost_1_90_0\boost\iterator\iterator_facade.hpp(500,18): note: in instantiation
of member function 'boost::compute::constant_iterator<int>::dereference' requested here
500 | return f.dereference();
| ^
...\boost_1_90_0\boost\iterator\iterator_facade.hpp(598,38): note: in instantiation
of function template specialization
'boost::iterators::iterator_core_access::dereference<boost::compute::constant_iterator<int>>' requested here
598 | return iterator_core_access::dereference(this->derived());
| ^
...\t.cpp(6,10): note: in instantiation of member function
'boost::iterators::detail::iterator_facade_base<boost::compute::constant_iterator<int>, int,
std::random_access_iterator_tag, int &, long long, false, false>::operator*' requested here
6 | return *ci;
| ^
1 error generated.
The relevant code from the constant_iterator.hpp header file is excerpted below (From https://github.com/boostorg/compute/blob/boost-1.90.0/include/boost/compute/iterator/constant_iterator.hpp):
34 template<class T>
35 class constant_iterator_base
36 {
37 public:
38 typedef ::boost::iterator_facade<
39 ::boost::compute::constant_iterator<T>,
40 T,
41 ::std::random_access_iterator_tag
42 > type;
43 };
..
59 template<class T>
60 class constant_iterator : public detail::constant_iterator_base<T>::type
61 {
..
63 typedef typename detail::constant_iterator_base<T>::type super_type;
64 typedef typename super_type::reference reference;
..
111 reference dereference() const
112 {
113 return m_value;
114 }
...
147 T m_value;
...
149 };
Iterator dereference for constant_iterator is implemented by the dereference() member. The problem is that reference is defined as T&. When T is a non-const type, then reference is a reference to a non-const type and the attempt to bind m_value in the return statement fails because dereference() is a const member function and m_value is therefore const-qualified when accessed within its definition.
This issue can probably be fixed in the definition of constant_iterator_base by passing an appropriately const-qualified type as the argument for the Reference template parameter of iterator_facade. For example:
34 template<class T>
35 class constant_iterator_base
36 {
37 public:
38 typedef ::boost::iterator_facade<
39 ::boost::compute::constant_iterator<T>,
40 T,
-41 ::std::random_access_iterator_tag
+++ ::std::random_access_iterator_tag,
+++ const T&
42 > type;
43 };
It seems the test_constant_iterator.cpp test fails to exercise the iterator dereference operation, presumably due to boost::compute::copy() using a different operation such as operator[].
- Ngôn ngữ chính
- C++
- Star
- 1.7k
- Fork
- 340
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của boostorg/compute
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Tất cả issue của boostorg/compute
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
patrick-hudson/put.gd-desktop#2044 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
uxlfoundation/oneDNN#6604 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Có thể đã có người làm @fmu1337 đã nhận hôm nay. Đang mởBug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
alliedmodders/sourcemod#2627 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
lballabio/QuantLib#3134 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày