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 conversion warning in xrepeat #2732

Merged
merged 3 commits into from
Oct 15, 2023
Merged

Fix conversion warning in xrepeat #2732

merged 3 commits into from
Oct 15, 2023

Conversation

bredej
Copy link
Contributor

@bredej bredej commented Oct 2, 2023

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • API of new functions and classes are documented.

Description

The internal type of std::accumulate is determined by the init parameter.
Initializing with 0 (int) results in a "conversion from 'size_t' to 'type', possible loss of data" warning in MSVC.
Here is a link showcasing the warning in Compiler Explorer.

@tdegeus
Copy link
Member

tdegeus commented Oct 10, 2023

Thanks! Though are you actually initialising to zero?

@bredej
Copy link
Contributor Author

bredej commented Oct 10, 2023

From Zero-initialization on cppreference.com:
* If T is a scalar type, the object is initialized to the value obtained by explicitly converting the integer literal ​0​ (zero) to T.

Or to be explicit about the init value
shape_value_type{0}

@tdegeus
Copy link
Member

tdegeus commented Oct 11, 2023

Let's do it explicitly for readability. Also shape_value_type(0) is equally permitted right (which I personally find more readable, avoiding any suggestion of an array.

@bredej
Copy link
Contributor Author

bredej commented Oct 13, 2023

@tdegeus I have made the change you suggested.

Copy link
Member

@tdegeus tdegeus left a comment

Choose a reason for hiding this comment

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

Thanks

@tdegeus tdegeus merged commit 283f2b8 into xtensor-stack:master Oct 15, 2023
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants