Comments (8)
It looks like changing the definition of elsa
to this fixes it for 32-bit MSVC. I assume that it would be more complicated for 64-bit, since it would have to do a 128-bit add. Unfortunately there doesn't appear to be any way to suppress the warning inside elsa
itself, if it's called in a constexpr
context, since the warning is raised at the point of use, not at its own code.
#if defined(_MSC_VER) && !defined(_WIN64)
constexpr std::size_t operator()(T const &value, std::size_t seed) const {
std::size_t key = seed ^ static_cast<std::size_t>(value);
key = static_cast<std::size_t>(static_cast<uint64_t>(~key) + (key << 21));
key = key ^ (key >> 24);
key = static_cast<std::size_t>(static_cast<uint64_t>(key) + (key << 3) + (key << 8));
key = key ^ (key >> 14);
key = static_cast<std::size_t>(static_cast<uint64_t>(key) + (key << 2) + (key << 4));
key = key ^ (key >> 28);
key = static_cast<std::size_t>(static_cast<uint64_t>(key) + (key << 31));
return key;
}
#else
constexpr std::size_t operator()(T const &value, std::size_t seed) const {
std::size_t key = seed ^ static_cast<std::size_t>(value);
key = (~key) + (key << 21); // key = (key << 21) - key - 1;
key = key ^ (key >> 24);
key = (key + (key << 3)) + (key << 8); // key * 265
key = key ^ (key >> 14);
key = (key + (key << 2)) + (key << 4); // key * 21
key = key ^ (key >> 28);
key = key + (key << 31);
return key;
}
#endif
from frozen.
I'd say overflow on a plus on unsigned type is not an issue because it's perfectly defined (unlike the signed version). What could be done instead of your cast is to apply a mask, as in (~key + (key << 21)) & ~std::size_t(0)
, does that silent the warning? or maybe static_caststd::size_t(~key + (key << 21)` ? If either of these work, feel free to open a PR!
from frozen.
No, those don't help; but I wouldn't really expect them to, since the warning is raised for the +
operator itself, not the assignment back into key
.
from frozen.
@serge-sans-paille clang-cl doesn't warn on this. Maybe just suppress the warning?
from frozen.
Sadly the warning is raised at point of constexpr
variable use, not anywhere inside elsa
itself, as I mentioned above. This makes it impossible to suppress the warning inside the library, except by changing the operand types of + as proposed above so that overflow can't occur.
I did file a bug with MS about the warning behaviour, so we can just sit on it and see if anything comes of that.
from frozen.
from frozen.
@serge-sans-paille Yes, something like this, there are various options, more or less portable.
from frozen.
@degski So, how many different ways do you want me to tell you that pragma suppressions don't work? Because this is the third time I've said that.
from frozen.
Related Issues (20)
- Support for std::array? HOT 2
- Warning concerning a missing constexpr HOT 3
- [Windows][VS][MSVC] Compilation failed - min / max macros HOT 2
- Add map/set final() method? HOT 5
- Status of cvector and carray
- Building tests fail because of incompatible catch2 version. HOT 1
- How to create a string key at runtime? HOT 5
- Frozen bimap? HOT 2
- Frozen constexpr map AVL tree ?
- Test compilation error HOT 5
- map::at() may return incorrect item HOT 1
- What are extended versions of `unordered_map::find`/`at` are for? HOT 1
- test_unordered_set.cpp failed to be built with gcc 12.2.0 HOT 4
- test_unordered_map.cpp: error: modification of 'ze_map' is not a constant expression; error: non-constant condition for static assertion HOT 2
- Cannot find frozen with `find_package(frozen REQUIRED)`
- CTAD issue using frozen::map HOT 1
- Does it work on gcc13? HOT 2
- Which version should I use? HOT 1
- implicit size like std::to_array HOT 1
- Generate an error when duplicate keys are present HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frozen.