Boost :: any_range <gsl :: string_span <> Release mode crash

I observe a rather strange behavior of the following code fragment:

#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/any_range.hpp>

#include <vector>
#include <string>
#include <iostream>

#include "gsl.h"

template <typename T>
using ImmutableValueRange = boost::any_range<T, boost::bidirectional_traversal_tag, /*const*/ T>;

template <typename T, typename C>
ImmutableValueRange<T> make_transforming_immutable_range(const C& container)
{
    return container | boost::adaptors::transformed([](const typename C::value_type& v) -> T 
    {
        //std::cout << "trans : " << T{ v }.data() << "\n";
        return T{ v }; 
    });
}

void f(ImmutableValueRange<gsl::cstring_span<>> r)
{
    for (const auto& c : r) {
        std::cout << c.data() << "\n";
    }
}

int main()
{
    std::vector<std::string> v({ "x", "y", "z" });

    f(make_transforming_immutable_range<gsl::cstring_span<>>(v));
}

The idea here is to isolate the actual representation of the string sequence, which is taken as a parameter by the function fbehind any_rangeand gsl::string_span(note that the commit changes string_viewto string_spanwas done a couple of hours ago by GSL).

const T Reference any_range ( T), . , Debug RelWithDebInfo ( CMake). VS2013/2015 x64. , Release, , (, ). const T Reference.

, , ? VS? string_span? boost::any_range?

Edit

clang 3.7.0, ( , const T -O2). , .

+4
2

, any_range dereference T, Reference const T, . - any_incrementable_iterator_interface::mutable_reference_type_generator, any_iterator_interface.hpp.

, const T Reference , .

+2

, . , std::string const :

const typename C::value_type& v

v cstring_span. rub: cstring_span , (, std::string). :

template <class Cont> cstring_span(Cont& c)

, , , v, cstring_span, . , , cstring_span .

0

Source: https://habr.com/ru/post/1614528/


All Articles