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

ref qualify parser methods to avoid use of dangling objects #703

Merged
merged 11 commits into from
Apr 15, 2020

Conversation

pauldreik
Copy link
Member

To avoid using data belonging to a temporary, the parse functions are ref qualified to get a compile error if used on an rvalue. See #696

I tried to understand the existing fail to compile tests, but I am not sure how the example without exceptions is intended to work, is it supposed to be a mirror of the working example code ? I am worried that having too much code in a fail to compile code means it is likely to fail due to for instance api changes, and one falsely believes everything is fine.
So I stole the concept and (hopefully:-) improved on it by keeping each file small, with as little code as possible changing between the "supposed to compile" code and "supposed to fail" code. See this pull request as the start of a discussion! Could you @jkeiser please have a look?

Perhaps the deleted overloads should have doxygen comments or a regular comment so people seeing reference qualifications for the first time are not surprised?

I had to update the benchmark which correctly used a temporary, this is a consequence of using this technique to capture the #696 type of mistakes. This means this is potentially a breaking change, but it results in a failed compile so it will be easy to fix.

In case the technique in this pull request is accepted, perhaps the release notes should say something about it so people are not surprised when it stops compiling.

@lemire
Copy link
Member

lemire commented Apr 13, 2020

1

@jkeiser
Copy link
Member

jkeiser commented Apr 14, 2020

It sounds like a great thing! I presume this means it'll also work on pointers with parser->parse()?

tests/CMakeLists.txt Outdated Show resolved Hide resolved
@jkeiser
Copy link
Member

jkeiser commented Apr 14, 2020

I tried to understand the existing fail to compile tests, but I am not sure how the example without exceptions is intended to work, is it supposed to be a mirror of the working example code ? I am worried that having too much code in a fail to compile code means it is likely to fail due to for instance api changes, and one falsely believes everything is fine.

You are absolutely right, the failure tests should be individual examples. The lazy way out definitely could miss something!

@jkeiser
Copy link
Member

jkeiser commented Apr 14, 2020

Perhaps the deleted overloads should have doxygen comments or a regular comment so people seeing reference qualifications for the first time are not surprised?

Honestly, I'd hide them in doxygen and document the limitation in the normal variant--having delete variants in doxygen confuses me (maybe it's just me).

@jkeiser
Copy link
Member

jkeiser commented Apr 14, 2020

I had to update the benchmark which correctly used a temporary, this is a consequence of using this technique to capture the #696 type of mistakes. This means this is potentially a breaking change, but it results in a failed compile so it will be easy to fix.

I think it's fine! I've been super worried about the temporary issue, and didn't realize there was a way to do this. This makes me even more comfortable than before.

Copy link
Member

@jkeiser jkeiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great work, and makes me feel more solid about the API!

Super minor requests for the most part. Maybe consider changing the structure of the failure tests to just be failures.

@pauldreik
Copy link
Member Author

It sounds like a great thing! I presume this means it'll also work on pointers with parser->parse()?

Glad you liked it! Yes, parser->parse() works fine with this change.

@pauldreik pauldreik merged commit 75545ff into master Apr 15, 2020
@pauldreik pauldreik deleted the paul/issue696 branch April 15, 2020 07:57
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.

3 participants