Don't dereference the end iterator when async_connect exhausts the range.
diff --git a/asio/include/asio/impl/connect.hpp b/asio/include/asio/impl/connect.hpp index 471460d..5c8650f 100644 --- a/asio/include/asio/impl/connect.hpp +++ b/asio/include/asio/impl/connect.hpp
@@ -324,7 +324,8 @@ } handler_(static_cast<const asio::error_code&>(ec), - static_cast<const typename Protocol::endpoint&>(*iter)); + static_cast<const typename Protocol::endpoint&>( + ec || iter == end ? typename Protocol::endpoint() : *iter)); } }