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

potential fix for std::variant implicit conversion in C++17 STL #734

Closed
wants to merge 2 commits into from

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented May 10, 2021

Fixes ##733

Changes

@maxgolov This is not for merge, but to showcase the potential changes needed to fix #733, As mentioned in the comment there, this is not related to resource sdk.

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@lalitb lalitb added the pr:do-not-merge This PR is not ready to be merged. label May 10, 2021
@lalitb lalitb requested a review from a team May 10, 2021 15:53
@lalitb lalitb marked this pull request as draft May 10, 2021 15:54
@codecov
Copy link

codecov bot commented May 10, 2021

Codecov Report

Merging #734 (b12a746) into main (840701b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #734   +/-   ##
=======================================
  Coverage   96.00%   96.01%           
=======================================
  Files         176      176           
  Lines        7183     7199   +16     
=======================================
+ Hits         6896     6912   +16     
  Misses        287      287           
Impacted Files Coverage Δ
exporters/ostream/test/ostream_log_test.cc 100.00% <100.00%> (ø)
exporters/ostream/test/ostream_span_test.cc 100.00% <100.00%> (ø)
sdk/src/resource/resource.cc 84.00% <100.00%> (+1.39%) ⬆️
sdk/test/resource/resource_test.cc 93.69% <100.00%> (+0.83%) ⬆️
sdk/test/trace/tracer_test.cc 99.45% <100.00%> (+<0.01%) ⬆️

Copy link
Contributor

@maxgolov maxgolov left a comment

Choose a reason for hiding this comment

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

I'm Okay with this as a temporary measure. I think we could have handled it in the AttributeValue class. I think the issue is that since it's a non-owning and always creates a string_view - this causes some odd issues with temporary arrays of chars..

@lalitb
Copy link
Member Author

lalitb commented May 10, 2021

I'm Okay with this as a temporary measure. I think we could have handled it in the AttributeValue class.

This is not related to AttributeValue. As an example, resource sdk doesn't use AttributeValue, but directly uses OwnedAttributeValue. The problem is with the implicit conversion of char * to bool in C++17, which seems to be corrected in C++20. I did some tests on std::variant, and it is actually storing string literal as a bool. Please see my comment on the issue you created.

@@ -150,7 +150,7 @@ TEST(OStreamLogExporter, LogWithStringAttributesToCerr)
auto record = exporter->MakeRecordable();

// Set resources for this log record only of type <string, string>
record->SetResource("key1", "val1");
record->SetResource("key1", std::string("val1"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we provide an explicit overload to SetResource with const char * to avoid potential future error?

Copy link
Contributor

@maxgolov maxgolov left a comment

Choose a reason for hiding this comment

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

I don't like that. I'm proposing to re-add const char * to variant. Just verified that it works, and including it in the Abseil Variant PR.

This re-add of const char * will give us much nicer user / developer experience, when we get to C++17 standard lib impl of variant.

@lalitb
Copy link
Member Author

lalitb commented May 20, 2021

I don't like that. I'm proposing to re-add const char * to variant. Just verified that it works, and including it in the Abseil Variant PR.

This re-add of const char * will give us much nicer user / developer experience, when we get to C++17 standard lib impl of variant.

Just to understand, we are seeing this issue both with C++17 STL and absl::variant, and mpark::variant handles this nicely ?

@lalitb
Copy link
Member Author

lalitb commented May 26, 2021

I don't like that. I'm proposing to re-add const char * to variant. Just verified that it works, and including it in the Abseil Variant PR.

This re-add of const char * will give us much nicer user / developer experience, when we get to C++17 standard lib impl of variant.

Sure closing this PR.

@lalitb lalitb marked this pull request as ready for review May 26, 2021 09:04
@lalitb lalitb marked this pull request as draft May 26, 2021 09:15
@lalitb lalitb closed this May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:do-not-merge This PR is not ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid pointer to reference to temporaries in SetResource API
3 participants