Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Iterators: Suppress "reference to temporary" warnings erroneously rep…
Browse files Browse the repository at this point in the history
…orted by

MSVC 2013 and 2015.
Bug 200385113
git-commit b93a7c51d5eb2259022f35ae5da92e47dbfc66e9
git-author Bryce Adelstein Lelbach aka wash <[email protected]>
VDVS: http://ausdvs.nvidia.com/Build_Results?virtualId=1000098256&which_page=current_build
ERIS: https://eris-portal.nvidia.com/fromJenkins.jsp?uuid=d22716bf-588d-4e80-8c16-c55f086a3796

Jobs: 200385113-2006
[git-p4: depot-paths = "//sw/gpgpu/thrust/": change = 23593362]
  • Loading branch information
brycelelbach committed Feb 14, 2018
1 parent 4b61388 commit d4b6eaa
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 38 deletions.
14 changes: 7 additions & 7 deletions thrust/iterator/constant_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace thrust
* #include <thrust/functional.h>
* #include <thrust/device_vector.h>
*
* int main(void)
* int main()
* {
* thrust::device_vector<int> data(4);
* data[0] = 3;
Expand Down Expand Up @@ -117,8 +117,8 @@ template<typename Value,
* null constructor.
*/
__host__ __device__
constant_iterator(void)
: super_t(), m_value(){};
constant_iterator()
: super_t(), m_value() {}

/*! Copy constructor copies the value of another \p constant_iterator into this
* \p constant_iterator.
Expand Down Expand Up @@ -173,24 +173,24 @@ template<typename Value,
* \return A \c const reference to this \p constant_iterator's constant value.
*/
__host__ __device__
Value const& value(void) const
Value const& value() const
{ return m_value; }

/*! \cond
*/

protected:
__host__ __device__
Value const& value_reference(void) const
Value const& value_reference() const
{ return m_value; }

__host__ __device__
Value & value_reference(void)
Value & value_reference()
{ return m_value; }

private: // Core iterator interface
__host__ __device__
reference dereference(void) const
reference dereference() const
{
return m_value;
}
Expand Down
6 changes: 3 additions & 3 deletions thrust/iterator/counting_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace thrust
* #include <thrust/functional.h>
* #include <thrust/device_vector.h>
*
* int main(void)
* int main()
* {
* // this example computes indices for all the nonzero values in a sequence
*
Expand Down Expand Up @@ -149,7 +149,7 @@ template<typename Incrementable,
* counter using its null constructor.
*/
__host__ __device__
counting_iterator(void){};
counting_iterator() {}

/*! Copy constructor copies the value of another \p counting_iterator into a
* new \p counting_iterator.
Expand Down Expand Up @@ -186,7 +186,7 @@ template<typename Incrementable,
*/
private:
__host__ __device__
reference dereference(void) const
reference dereference() const
{
return this->base_reference();
}
Expand Down
2 changes: 1 addition & 1 deletion thrust/iterator/detail/any_assign.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace detail
// a type which may be assigned any other type
struct any_assign
{
inline __host__ __device__ any_assign(void)
inline __host__ __device__ any_assign()
{}

template<typename T>
Expand Down
2 changes: 1 addition & 1 deletion thrust/iterator/detail/counting_iterator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ template <typename Incrementable, typename System, typename Traversal, typename
// our implementation departs from Boost's in that counting_iterator::dereference
// returns a copy of its counter, rather than a reference to it. returning a reference
// to the internal state of an iterator causes subtle bugs (consider the temporary
// iterator created in the expression *(iter + i) ) and has no compelling use case
// iterator created in the expression *(iter + i)) and has no compelling use case
typedef thrust::iterator_adaptor<
counting_iterator<Incrementable, System, Traversal, Difference>, // self
Incrementable, // Base
Expand Down
6 changes: 6 additions & 0 deletions thrust/iterator/detail/join_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class join_iterator
private:
friend class thrust::iterator_core_access;

// MSVC 2013 and 2015 incorrectly warning about returning a reference to
// a local/temporary here.
// See goo.gl/LELTNp
__THRUST_DISABLE_MSVC_WARNING_BEGIN(4172)

__host__ __device__
typename super_t::reference dereference() const
Expand All @@ -108,6 +112,8 @@ class join_iterator
return (i < m_n1) ? m_iter1[i] : static_cast<typename super_t::reference>(m_iter2[i]);
} // end dereference()

__THRUST_DISABLE_MSVC_WARNING_END(4172)


size_type m_n1;
RandomAccessIterator1 m_iter1;
Expand Down
6 changes: 3 additions & 3 deletions thrust/iterator/detail/reverse_iterator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ template<typename BidirectionalIterator>
__host__ __device__
typename reverse_iterator<BidirectionalIterator>::super_t::reference
reverse_iterator<BidirectionalIterator>
::dereference(void) const
::dereference() const
{
return *thrust::detail::prior(this->base());
} // end reverse_iterator::increment()

template<typename BidirectionalIterator>
__host__ __device__
void reverse_iterator<BidirectionalIterator>
::increment(void)
::increment()
{
--this->base_reference();
} // end reverse_iterator::increment()

template<typename BidirectionalIterator>
__host__ __device__
void reverse_iterator<BidirectionalIterator>
::decrement(void)
::decrement()
{
++this->base_reference();
} // end reverse_iterator::decrement()
Expand Down
2 changes: 1 addition & 1 deletion thrust/iterator/detail/tagged_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ template<typename Iterator, typename Tag>

public:
__host__ __device__
tagged_iterator(void) {}
tagged_iterator() {}

__host__ __device__
explicit tagged_iterator(Iterator x)
Expand Down
14 changes: 8 additions & 6 deletions thrust/iterator/detail/zip_iterator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace thrust
template<typename IteratorTuple>
__host__ __device__
zip_iterator<IteratorTuple>
::zip_iterator(void)
::zip_iterator()
{
} // end zip_iterator::zip_iterator()

Expand Down Expand Up @@ -57,7 +57,7 @@ template<typename IteratorTuple>
template<typename IteratorTuple>
__host__ __device__
const IteratorTuple &zip_iterator<IteratorTuple>
::get_iterator_tuple(void) const
::get_iterator_tuple() const
{
return m_iterator_tuple;
} // end zip_iterator::get_iterator_tuple()
Expand All @@ -67,11 +67,13 @@ template<typename IteratorTuple>
typename zip_iterator<IteratorTuple>::super_t::reference
__host__ __device__
zip_iterator<IteratorTuple>
::dereference(void) const
::dereference() const
{
using namespace detail::tuple_impl_specific;

return thrust::detail::tuple_host_device_transform<detail::dereference_iterator::template apply>(get_iterator_tuple(), detail::dereference_iterator());
return thrust::detail::tuple_host_device_transform<
detail::dereference_iterator::template apply
>(get_iterator_tuple(), detail::dereference_iterator());
} // end zip_iterator::dereference()


Expand Down Expand Up @@ -100,7 +102,7 @@ __host__ __device__
template<typename IteratorTuple>
__host__ __device__
void zip_iterator<IteratorTuple>
::increment(void)
::increment()
{
using namespace detail::tuple_impl_specific;
tuple_for_each(m_iterator_tuple, detail::increment_iterator());
Expand All @@ -110,7 +112,7 @@ __host__ __device__
template<typename IteratorTuple>
__host__ __device__
void zip_iterator<IteratorTuple>
::decrement(void)
::decrement()
{
using namespace detail::tuple_impl_specific;
tuple_for_each(m_iterator_tuple, detail::decrement_iterator());
Expand Down
4 changes: 2 additions & 2 deletions thrust/iterator/discard_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace thrust
* #include <thrust/reduce.h>
* #include <thrust/device_vector.h>
*
* int main(void)
* int main()
* {
* thrust::device_vector<int> keys(7), values(7);
*
Expand Down Expand Up @@ -132,7 +132,7 @@ template<typename System = use_default>

private: // Core iterator interface
__host__ __device__
reference dereference(void) const
reference dereference() const
{
return m_element;
}
Expand Down
7 changes: 7 additions & 0 deletions thrust/iterator/permutation_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,20 @@ template <typename ElementIterator,
/*! \cond
*/
private:
// MSVC 2013 and 2015 incorrectly warning about returning a reference to
// a local/temporary here.
// See goo.gl/LELTNp
__THRUST_DISABLE_MSVC_WARNING_BEGIN(4172)

__thrust_exec_check_disable__
__host__ __device__
typename super_t::reference dereference() const
{
return *(m_element_iterator + *this->base());
}

__THRUST_DISABLE_MSVC_WARNING_END(4172)

// make friends for the copy constructor
template<typename,typename> friend class permutation_iterator;

Expand Down
8 changes: 4 additions & 4 deletions thrust/iterator/reverse_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ template<typename BidirectionalIterator>
/*! Default constructor does nothing.
*/
__host__ __device__
reverse_iterator(void) {}
reverse_iterator() {}

/*! \p Constructor accepts a \c BidirectionalIterator pointing to a range
* for this \p reverse_iterator to reverse.
Expand Down Expand Up @@ -195,13 +195,13 @@ template<typename BidirectionalIterator>
private:
__thrust_exec_check_disable__
__host__ __device__
typename super_t::reference dereference(void) const;
typename super_t::reference dereference() const;

__host__ __device__
void increment(void);
void increment();

__host__ __device__
void decrement(void);
void decrement();

__host__ __device__
void advance(typename super_t::difference_type n);
Expand Down
20 changes: 14 additions & 6 deletions thrust/iterator/transform_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace thrust
* }
* };
*
* int main(void)
* int main()
* {
* thrust::device_vector<float> v(4);
* v[0] = 1.0f;
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace thrust
* }
* };
*
* int main(void)
* int main()
* {
* // initialize a device array
* thrust::device_vector<float> v(4);
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace thrust
* }
* };
*
* int main(void)
* int main()
* {
* thrust::device_vector<float> v(4);
* v[0] = 1.0f;
Expand Down Expand Up @@ -296,16 +296,24 @@ template <class AdaptableUnaryFunction, class Iterator, class Reference = use_de
return *this;
}

// MSVC 2013 and 2015 incorrectly warning about returning a reference to
// a local/temporary here.
// See goo.gl/LELTNp
__THRUST_DISABLE_MSVC_WARNING_BEGIN(4172)

__thrust_exec_check_disable__
__host__ __device__
typename super_t::reference dereference() const
{
// create a temporary to allow iterators with wrapped references to convert to their value type before calling m_f
// note that this disallows non-constant operations through m_f
{
// Create a temporary to allow iterators with wrapped references to
// convert to their value type before calling m_f. Note that this
// disallows non-constant operations through m_f.
typename thrust::iterator_value<Iterator>::type x = *this->base();
return m_f(x);
}

__THRUST_DISABLE_MSVC_WARNING_END(4172)

// tag this as mutable per Dave Abrahams in this thread:
// http://lists.boost.org/Archives/boost/2004/05/65332.php
mutable AdaptableUnaryFunction m_f;
Expand Down
6 changes: 4 additions & 2 deletions thrust/iterator/transform_output_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace thrust
* }
* };
*
* int main(void)
* int main()
* {
* thrust::device_vector<float> v(4);
*
Expand Down Expand Up @@ -125,7 +125,9 @@ template <typename UnaryFunction, typename OutputIterator>
__host__ __device__
typename super_t::reference dereference() const
{
return detail::transform_output_iterator_proxy<UnaryFunction, OutputIterator>(this->base_reference(), fun);
return detail::transform_output_iterator_proxy<
UnaryFunction, OutputIterator
>(this->base_reference(), fun);
}

UnaryFunction fun;
Expand Down
4 changes: 2 additions & 2 deletions thrust/iterator/zip_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace thrust
* #include <thrust/tuple.h>
* #include <thrust/device_vector.h>
*
* int main(void)
* int main()
* {
* thrust::device_vector<int> int_in(3), int_out(3);
* int_in[0] = 0;
Expand Down Expand Up @@ -144,7 +144,7 @@ template <typename IteratorTuple>
/*! Null constructor does nothing.
*/
inline __host__ __device__
zip_iterator(void);
zip_iterator();

/*! This constructor creates a new \p zip_iterator from a
* \p tuple of iterators.
Expand Down

0 comments on commit d4b6eaa

Please sign in to comment.