Skip to content

Conversation

@umogSlayer
Copy link

a) fixes warnings issued by MSVC (warning C4127: conditional expression is
constant),
b) removes runtime "signedness" check for integer-like types.

template<typename int_type>
using IsSignedIntType =
std::is_signed<
typename std::conditional_t<

Choose a reason for hiding this comment

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

conditional_t is a C++14 API. Gotta wait a few more years before we can rely on that in Abseil, I'm afraid.
That said, absl/meta/type_traits.h has an absl::conditional_t.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

}

template<typename any_type>
struct Identity final

Choose a reason for hiding this comment

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

This already exists in absl/base/internal/identity.h - maybe it should just move to meta/type_traits? Regardless, for now you should use that one.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

Identity<int_type>>::type>;

template<typename int_type>
using PrintableIntType =

Choose a reason for hiding this comment

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

PrintableIntType is a slightly weird name for this - it's printable only in the sense that we've written overloads for it.

Perhaps something more like IntToSupportedInt or IntTo32Or64? I'd definitely name it more actively - it's more metafunction than type.

Copy link
Author

Choose a reason for hiding this comment

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

Renamed to IntLikeTo32Or64, wrote a comment explaining meaning of this metafunction.

*out = static_cast<int_type>(val);
}
}
using ParsedType = numbers_internal::PrintableIntType<int_type>;

Choose a reason for hiding this comment

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

ParsedType seems like an odd name: it isn't parsed from anything. SupportedInt?

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good to me. Fixed.

Copy link

@tituswinters tituswinters left a comment

Choose a reason for hiding this comment

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

I'll also try to get the original maintainer of this to take a look.

I'm curious: is this not being optimized already? Is this just to address the warnings on MSVC?

@umogSlayer
Copy link
Author

Thanks for comments.
Basically yes, it's mainly to address MSVC warnings since optimizers should optimize that code away.
But interestingly enough this code generates 2 warnings on MSVC, the one I wrote and narrowing type conversion warning (this one I don't want to disable). Narrowing type conversion happens because (as it seems) compiler front-end generates all the code paths and on dead paths we actually have narrowing conversion.

@tituswinters
Copy link

Update: we're looking at various options for potentially restructuring that to address the MSVC warnings - we might go this way or we might find a different refactoring. I expect it'll get resolved/decided by early next week either way.

@tituswinters
Copy link

The internal maintainer took a different approach, which I think should still resolve the MSVC warnings you were seeing. Check the current HEAD and see if that resolves your issue? If not, we'll finish this off next week. Thanks.

@umogSlayer
Copy link
Author

I've looked at current master branch and those changes don't address the C4127: conditional expression is constant warning. Since this line of code hasn't been changed: if (sizeof(i) > 32 / 8) {. But they address the narrowing cast warning.

…mbers.h

a) fixes warnings issued by MSVC (warning C4127: conditional expression is
constant),
b) removes runtime signedness check for integer-like types.
@umogSlayer
Copy link
Author

I've changed my code a bit. Maybe this version is ok.

@umogSlayer
Copy link
Author

I have one question though. After implementing these changes I have failing tests. Is it intended use of FastIntToBuffer with custom "integer wrapper" like MyInteger at numbers_test.cc:111?

@tituswinters
Copy link

Since it's internal, I guess that could in theory be relaxed. But I do like the more-explicit code as-is.

Here's a thought: can we just #pragma suppress the MSVC warning for that block? That feels potentially less awkward to me, overall.

@johnforestolson
Copy link
Contributor

Hello! Following up on this PR. Vladimir, any thoughts on Titus' suggestion?

@ahedberg
Copy link
Contributor

ahedberg commented Apr 2, 2018

One more ping on this PR - any thoughts on Titus' suggestion, @umogSlayer? Are you still seeing MSVC warnings, and would #pragma suppression clear them up?

I'm inclined to close this PR by the end of the week if it remains inactive.

@umogSlayer
Copy link
Author

Hello!
Sorry for such a late response, had basically no time lately.

I don't like the idea to disable warnings for blocks of code. It seems to me that such approach is not scalable, if someone in clang or gcc adds the same warning then you'll need to handle that case separately.

Maybe it's better to use something like if constexpr (...) simulation?

@ahedberg
Copy link
Contributor

Apologies for the delay in following up here.

We're still leaning towards the pragma solution. The warnings are all false in those cases, and disabling them locally is safe and correct. A SFINAE-based solution feels excessive here. Thoughts?

@ahedberg
Copy link
Contributor

Given the lack of activity on this PR, I think we should close it--please reopen if you're still seeing MSVC warnings.

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.

5 participants