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

A lot of code assumes that string_view::iterator is const char*. Does not work on every compiler #2323

Open
hzeller opened this issue Jan 12, 2025 · 0 comments
Assignees

Comments

@hzeller
Copy link
Collaborator

hzeller commented Jan 12, 2025

A lot of code within Verible assumes that the iterator of string_view just decays to const char*. This assumption was true while absl::string_view was the implementation used, and even after switching to c++17, is as well true for gcc/clang standard library std::string_view.

However, on Windows, the iterator is its own wrapper object that can not be assigned to const char*, so Verible would fail to compile if we used that std::string_view there.

Thus, for a long while, we have a patch to tell abseil to always use the internal absl::string_view internal implementation on Windows and not just typedef absl::string_view to std::string_view.

However, due to that patch, our abseil-cpp in MODULES.bazel deviates from others users that depend on Verible in the registry. Not sure if this will be a problem, but it is an additional reason to get this fixed.

It would be good to remove these assumptions. This will probably involve using absl::string_view::iterator instead of const char* for parameters and data members where the intent is to work with iterators.

Also construction of std::string_view's that use iterators as start point will be different.

   absl::string_view foo0(bar.begin(), 42);  // before
   absl::string_view foo1(&*bar.begin(). 42);  // after (somewhat ugly)
   absl::string_view foo2(bar.data(), 42);  // slightly less ugly, but only works if we know it's begin.

This is a collection issue to collect all the pull requests towards that goal until everything is done.

Exit criteria: we can replace all absl::string_view with std::string_view and code compiles on all platforms.

@hzeller hzeller self-assigned this Jan 12, 2025
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 12, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 13, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 13, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

Issues: chipsalliance#2323
hzeller added a commit to hzeller/verible that referenced this issue Jan 13, 2025
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

We also have a `string_view_null_iterator()` function to generate
an iterator that is not initialized to be used in place where we
previously used comparison against nullptr.

Issues: chipsalliance#2323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant