Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropping from an empty sequence asserts #132

Closed
JohelEGP opened this issue Nov 17, 2023 · 3 comments · Fixed by #134
Closed

Dropping from an empty sequence asserts #132

JohelEGP opened this issue Nov 17, 2023 · 3 comments · Fixed by #134
Assignees
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link

An assertion is triggered due to the drop in intersperse.
See https://cpp1.godbolt.org/z/ff99sqcK5:

#include "https://raw.githubusercontent.com/tcbrindle/flux/main/single_include/flux.hpp"

using namespace flux;

auto intersperse(auto&& r, auto&& e) -> auto { return FLUX_FWD(r).map([_0 = e](auto const& x) -> auto { return std::vector{_0, x};  }).flatten().drop(1);  }

auto sfml_argument(std::string_view) -> std::string { return "abc";  }

auto sfml_argument_list(std::span<std::string_view> mf) -> std::string { 
    return "(" + intersperse(drop(mf, 1).map(sfml_argument), std::string(", ")).flatten().to<std::string>() + ")";  }

auto main() -> int{
  std::vector<std::string_view> v {"point"}; 
  (void)sfml_argument_list(v);
}
/app/raw.githubusercontent.com/tcbrindle/flux/main/single_include/flux.hpp:1136: Fatal error: assertion 'self.has_value()' failed
terminate called without an active exception
Program terminated with signal: SIGSEGV

The same happens here (https://cpp1.godbolt.org/z/s4xGzzK3j):

#include "https://raw.githubusercontent.com/tcbrindle/flux/main/single_include/flux.hpp"

#include <array>
#include <iostream>
#include <iterator>

int main()
{
    auto result = flux::from(std::array{1, 2})
                                .filter(flux::pred::even)
                                .drop(2)
                                .drop(1);
    result.output_to(std::ostream_iterator<int>{std::cout});
}
@tcbrindle
Copy link
Owner

Hi @JohelEGP, thanks for the bug report. Something definitely seems to be going wrong here. I'll look into it.

@tcbrindle tcbrindle self-assigned this Nov 22, 2023
@tcbrindle tcbrindle added the bug Something isn't working label Nov 22, 2023
tcbrindle added a commit that referenced this issue Nov 27, 2023
If we passed a positive offset to the non-RA version of advance(), we were performing an inc() on the passed-in cursor without first checking whether it was at the end.

So let's not do that.

Fixes #132
tcbrindle added a commit that referenced this issue Nov 27, 2023
If we passed a positive offset to the non-RA version of advance(), we were performing an inc() on the passed-in cursor without first checking whether it was at the end.

So let's not do that.

Fixes #132
@tcbrindle
Copy link
Owner

This should now be fixed. Thanks again for the bug report!

@JohelEGP
Copy link
Author

Thank you!
I can confirm it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants