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

[params] Runtime error when casting string param to const char* #614

Open
galexv opened this issue Apr 9, 2019 · 0 comments
Open

[params] Runtime error when casting string param to const char* #614

galexv opened this issue Apr 9, 2019 · 0 comments
Assignees

Comments

@galexv
Copy link
Collaborator

galexv commented Apr 9, 2019

The following code:

#include <alps/params.hpp>
using alps::params;
using std::string;

///Some function that requires a C string
void consume_c_str(const char*) {}

int main(int argc, char**argv) {
  params p(argc,argv);
  p.define<string>("str", "default", "A string param");
  // Attempt to pass a parameter as a C-string
  consume_c_str(p["str"]); // Throws!
  // Attempt to obtain a C string:
  const char* my_c_str=p["str"]; // Throws!
}

throws type_mismatch exception about illegal attempted conversion from string to char*.
This looks like a bug: either it should perform the conversion and return a const char* pointer to the underlying string (whether it's a good idea is a different question), or it should fail at compile time, as it does with other unsupported types.

@galexv galexv added the bug label Apr 9, 2019
@galexv galexv self-assigned this Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant