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

Fix std::string_view support in transforming validators #300

Merged
merged 5 commits into from
Jul 25, 2019

Conversation

peterazmanov
Copy link
Contributor

Transforming validators convert const char * to std::string, but don't do the same for std::string_view. This causes UB in details::lexical_cast that returns std::string_view holding dangling pointer.

@codecov
Copy link

codecov bot commented Jul 25, 2019

Codecov Report

Merging #300 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #300   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          12     12           
  Lines        2880   2880           
=====================================
  Hits         2880   2880
Impacted Files Coverage Δ
include/CLI/TypeTools.hpp 100% <ø> (ø) ⬆️
include/CLI/Validators.hpp 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6aca64...81e5393. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 25, 2019

Codecov Report

Merging #300 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #300   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          12     12           
  Lines        2880   2886    +6     
=====================================
+ Hits         2880   2886    +6
Impacted Files Coverage Δ
include/CLI/TypeTools.hpp 100% <ø> (ø) ⬆️
include/CLI/Validators.hpp 100% <100%> (ø) ⬆️
include/CLI/App.hpp 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6aca64...f2fa90a. Read the comment docs.

@henryiii
Copy link
Collaborator

I'm thinking of moving the string_view part to the test, and using CLI11 + StringView would require a user add the overload. I'm not fond of adding a new include, it adds a dependency that can sometimes fail (as seen in the tests). I was hoping I could add a declaration instead of an include, but I'm not sure how to do that since it's really std::__1::basic_string_view and I don't think I want to rely on the __1 being there.

The other change is fine, adding a test is fine, and it might be something improved by #285.

@peterazmanov
Copy link
Contributor Author

I'm not fond of adding a new include, it adds a dependency that can sometimes fail (as seen in the tests).

std::string actually includes <string_view> for __cplusplus >= 201703L. So there is no additional overhead.

... and using CLI11 + StringView would require a user add the overload.

I don't know how to prevent usage of std::string_view without adding the overload.

I was hoping I could add a declaration instead of an include, but I'm not sure how to do that since it's really std::__1::basic_string_view and I don't think I want to rely on the __1 being there.

AFAIK adding forward declarations for STL classes is not allowed by the standard.

@henryiii
Copy link
Collaborator

henryiii commented Jul 25, 2019

std::string actually includes <string_view> for __cplusplus >= 201703L. So there is no additional overhead.

I don't think that's required, but it's good enough for me.

AFAIK adding forward declarations for STL classes is not allowed by the standard.

Yes, I believe so, which is why they are fine to put them in inline namespaces...

it adds a dependency that can sometimes fail (as seen in the tests)

Okay, this was my mistake, now it looks fine.

@henryiii henryiii merged commit f0c0794 into CLIUtils:master Jul 25, 2019
henryiii added a commit to phlptp/CLI11 that referenced this pull request Jul 27, 2019
henryiii added a commit to phlptp/CLI11 that referenced this pull request Jul 27, 2019
henryiii pushed a commit that referenced this pull request Jul 29, 2019
* add some tests with default capture on the two parameter template and some notes about it in the README.md

remove the test from visual studio 2015
vs2015 doesn't seem to properly deal with is_assignable in the cases we care about so make a standalone version that is more direct in what we are doing

add version to appveyor and add some notes to the readme

fix a few test cases to make sure code is covered and test a few other paths

remove unneeded enum streaming operator

add some diagnostic escapes around trait code to eliminate gcc Wnarrowing warnings

work specification of the template operations

remove optional add some templates for options conversions

add the two parameter template for add_option

* Fix some comments from Code review and add more description

* fix case when string_view doesn't work to append to a string.

* This PR also addressed #300

* modify lexical_cast to take  const std::string &, instead of by value to allow string_view in a few cases
@henryiii henryiii added this to the v1.9 milestone Dec 31, 2019
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

Successfully merging this pull request may close these issues.

2 participants