ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

views::join terminates program because of noexcept clause #1751

Closed anish1979 closed 1 year ago

anish1979 commented 1 year ago

The following program terminates abnormally due to exception throw despite the presence of try-catch block:

static std::vector<char> conv(std::vector<char> inp)
{
    return {}; 
}
static std::vector<char> finish()
{
    return {}; 
}
int main()
{
    try {
        std::vector<char> const vi{'a', 'b', 'c', 'd', 'e', 'f'};
        auto rng = ranges::views::concat(vi
              |    ranges::views::chunk(2)
              | ranges::views::transform([](auto&& chs){
                    throw std::runtime_error("");
                    return conv(chs | ranges::to<std::vector<char>>);
              }) | ranges::views::cache1,
                ranges::views::generate_n([]() {
                    return finish();
                }, 1)) 
            | ranges::views::join;
        std::cout << rng << std::endl;
    }   
    catch(...)
    {   
        std::cout << "exception occurred.";
    }   
}

This is because of the following code in view/join.hpp:

         // Intentionally promote xvalues to lvalues here:
         template<typename OuterIt>
         static constexpr auto && update_inner_(OuterIt && it) noexcept
         {
             return *it;
         }

I think it should be:

         // Intentionally promote xvalues to lvalues here:
         template<typename OuterIt>

        static constexpr auto && update_inner_(OuterIt && it) noexcept(noexcept(*it))
         {
             return *it;
         }