Skip to content

C++ - problem with string_view with some functions #189

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

Closed
polidobj opened this issue Mar 20, 2025 · 2 comments
Closed

C++ - problem with string_view with some functions #189

polidobj opened this issue Mar 20, 2025 · 2 comments
Assignees
Labels
backend bug Something isn't working C++

Comments

@polidobj
Copy link

I'm getting errors with some functions when passing them a string_view. I think the issue is the same as this one:
https://www.devgem.io/posts/handling-std-string-view-with-std-fstream-in-c-why-doesn-t-it-work

The places that I've seen this so far are with unordered_map's add, erase and clear. And also with the std::runtime_error.

Here's a testcase:


public class A
{
  Dictionary<string, int>() dict;
  
  public void Add(string key, int value) throws Exception
  {
    if(dict.ContainsKey(key))
      throw Exception(key);
    dict[key] = value;
  }

}

@pfusik pfusik self-assigned this Mar 20, 2025
@pfusik pfusik added bug Something isn't working backend C++ labels Mar 20, 2025
pfusik added a commit that referenced this issue Mar 20, 2025
@pfusik
Copy link
Collaborator

pfusik commented Mar 20, 2025

I have fixed passing a string reference to Exception.

Dictionary mutators do work. The problem is that you attempt to modify a field from a non-mutating method. Your code should be:

public void Add!(string key, int value) throws Exception

This is a common error, which should be reported by fut rather than the C++ compiler -- I will work on it.

@polidobj
Copy link
Author

Thanks. I thought I saw some inconsistency with the enforcing mutating methods. But I had not figured it out enough to file an issue.

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

No branches or pull requests

2 participants