[SERVER-29887] clang-4.0 warns about std::max(0u, variable) in geo code Created: 28/Jun/17  Updated: 30/Oct/23  Resolved: 26/Jul/17

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: None
Fix Version/s: 3.5.11

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Mathias Stearn
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Repl 2017-07-31
Participants:

 Description   

This looks real, since that is almost certainly not what that code is actually trying to do:

[454/2741 ( 16%) 28.503s] CXX build/ninja/mongo/db/exec/geo_near.o
src/mongo/db/exec/geo_near.cpp:291:25: warning: taking the max of unsigned zero and a value is always equal to the other value [-Wmax-unsigned-zero]
        _currentLevel = std::max(0u, hashParams.bits - 1u);
                        ^~~~~~~~ ~~
src/mongo/db/exec/geo_near.cpp:291:25: note: remove call to max function and unsigned zero argument
        _currentLevel = std::max(0u, hashParams.bits - 1u);
                        ^~~~~~~~ ~~~
1 warning generated.
[643/2741 ( 23%) 35.820s] CXX build/ninja/mongo/db/geo/r2_region_coverer.o
src/mongo/db/geo/r2_region_coverer.cpp:73:17: warning: taking the max of unsigned zero and a value is always equal to the other value [-Wmax-unsigned-zero]
    _minLevel = max(0u, min(GeoHash::kMaxBits, minLevel));
                ^~~ ~~
src/mongo/db/geo/r2_region_coverer.cpp:73:17: note: remove call to max function and unsigned zero argument
    _minLevel = max(0u, min(GeoHash::kMaxBits, minLevel));
                ^~~ ~~~
src/mongo/db/geo/r2_region_coverer.cpp:79:17: warning: taking the max of unsigned zero and a value is always equal to the other value [-Wmax-unsigned-zero]
    _maxLevel = max(0u, min(GeoHash::kMaxBits, maxLevel));
                ^~~ ~~
src/mongo/db/geo/r2_region_coverer.cpp:79:17: note: remove call to max function and unsigned zero argument
    _maxLevel = max(0u, min(GeoHash::kMaxBits, maxLevel));
                ^~~ ~~~
2 warnings generated.



 Comments   
Comment by Githook User [ 26/Jul/17 ]

Author:

{'email': 'mathias@10gen.com', 'username': 'RedBeard0531', 'name': 'Mathias Stearn'}

Message: SERVER-29887 address clang-4.0 warnings in geo code
Branch: master
https://github.com/mongodb/mongo/commit/b35c594738261edce2134b0bc7fb3e7a06e85fc3

Comment by Githook User [ 14/Jul/17 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: Revert "SERVER-29887 address clang-4.0 warnings in geo code"

This reverts commit 8204c7dacf17851057dda165e6d1638cbff70cbf.
Branch: master
https://github.com/mongodb/mongo/commit/a9a2772d214b6839ebffaa8c547c1628ffe62e99

Comment by Githook User [ 13/Jul/17 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-29887 address clang-4.0 warnings in geo code
Branch: master
https://github.com/mongodb/mongo/commit/8204c7dacf17851057dda165e6d1638cbff70cbf

Comment by David Storch [ 30/Jun/17 ]

This is not a priority for the query team right now, but I'd be happy to review a patch. This code has been there for quite some time, and I'm not super familiar with it, but it did look like we could just remove the extra std::max() calls.

Comment by Mathias Stearn [ 30/Jun/17 ]

Can we get this in 3.5 required or at least desired? We generally try to ensure that our code is warning free on the latest compilers at the time of release to make it easier to work with over its full supported lifetime (in addition to the obvious correctness benefits).

Generated at Thu Feb 08 04:22:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.