New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 774200 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Email to this user bounced
Closed: Oct 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

warning: comparison of unsigned expression >= 0 is always true thrown while building for samus device

Project Member Reported by djacobo@chromium.org, Oct 12 2017

Issue description

While building for samus device, I noticed this:

service_worker_provider_host.cc:890:19: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
      if (feature >= 0 &&


Digging a big lead me to this recent review: 

https://chromium-review.googlesource.com/c/chromium/src/+/648659/15/content/browser/service_worker/service_worker_provider_host.cc

Maybe revert and redo this change?
 

Comment 1 by mcnee@chromium.org, Oct 12 2017

This warning doesn't appear to be causing any failures so reverting may not be necessary. I notice that in the comments of the original CL there was concern about |feature| becoming signed in the future and so the tautological compare was left in.

We could just do something like
|static_assert(std::is_unsigned<std::remove_reference<decltype(feature)>::type>::value, "feature must be unsigned");|
in order to make sure that |feature|'s sign doesn't change without being noticed. Then we can safely get rid of the tautological compare.
sgtm, thanks for investigating mcnee@ !
@menee, thanks a lot, your investigation is correct.
How to do this?
|static_assert(std::is_unsigned<std::remove_reference<decltype(feature)>::type>::value, "feature must be unsigned");|
We finally decide to create a CL now to fix this warning.

Comment 5 by falken@chromium.org, Oct 13 2017

Status: Started (was: Untriaged)
https://chromium-review.googlesource.com/717696
Project Member

Comment 6 by bugdroid1@chromium.org, Oct 13 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/4d47a13e3d98ef30d74ae3d4671d57c097b7124e

commit 4d47a13e3d98ef30d74ae3d4671d57c097b7124e
Author: xzhan96 <xiaofeng.zhang@intel.com>
Date: Fri Oct 13 06:37:44 2017

[ServiceWorker] Fix the warning for comparison of unsigned expression

The original comparison is for the case that used_features
will become signed in the future.

BUG= 774200 

Change-Id: I9607d44bd2163f260223b23c4bddac0891a5152f
Reviewed-on: https://chromium-review.googlesource.com/717696
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#508620}
[modify] https://crrev.com/4d47a13e3d98ef30d74ae3d4671d57c097b7124e/content/browser/service_worker/service_worker_provider_host.cc

Comment 7 by mcnee@chromium.org, Oct 13 2017

Thanks.

#3: The static_assert that I suggested would let you keep using auto for the type of |feature| and then it would cause a compiler error if |feature| ever became signed, so we would know to update the code to handle signed values.
But declaring the type to be unsigned also works, since you're still comparing |feature| with |kNumberOfFeatures|.
Status: Fixed (was: Started)

Sign in to add a comment