Comments (3)
Can you please paste this as text somehow? It seems HTML ate a lot of your
angle brackets :)
Also, what is the error that you're getting? Is it that hashstd::string
is already defined?
On Mon, Jul 7, 2014 at 8:02 PM, likan999 [email protected] wrote:
The following simple program will produce error under libc++:
#include
#include
#includeusing namespace std;
namespace std {
template
struct hashstd::basic_string : private hash {
size_t operator()(const std::basic_string & s) const {
return hash::operator()(s.c_str());
}
};
}const static unordered_map m = {
{"abc", 1},
{"xyz", 2},
};int main() {
assert(m.find("abc") != m.end());
}String.h shouldn't specialize hash function for libc++.
—
Reply to this email directly or view it on GitHub
#74.
from folly.
@tudor, the specialization is copied from String.h to demonstrate the problem. Simply including "String.h" can also reproduce the same issue. The error is the code successfully compiles under libc++ but at runtime the assertion fails. I guess the culprit is libc++ has a different hash implementation.
I guess the specialization was introduced when c++11 was not yet fully implemented by mainline compilers and hash was not available. But since hash is in C++11 standard, and major compilers supports c++11 faily well, it is no longer needed?
from folly.
You're right. Our specialization is actually broken! (because we make
hash call hash<const char*> on s.c_str(), which is clearly bad, as
hash<const char*> doesn't hash the strings, only the pointer value)
We haven't seen this at FB because libstdc++ provides full specializations
(as required by the standard), so hash is more specific than
template hash<basic_string>, so the libstdc++ specialization
wins.
Clearly libc++ does something different (and it's not fully standard
compliant), but, regardless, these specializations are unnecessary AND
broken, so I'll fix.
On Tue, Jul 8, 2014 at 9:51 AM, likan999 [email protected] wrote:
@tudor https://github.com/tudor, the specialization is copied from
String.h to demonstrate the problem. By simply including "String.h" can
also reproduce the same issue. The error is the code successfully compiles
under libc++ but at runtime the assertion fails. I guess the culprit is
libc++ has a different hash implementation.I guess the specialization was introduced when c++11 was not yet fully
implemented by mainline compilers and hash was not available. But since
hash is in C++11 standard, and major compilers supports c++11 faily well,
it is no longer needed?—
Reply to this email directly or view it on GitHub
#74 (comment).
from folly.
Related Issues (20)
- `small_vector.MoveAndCopyTrivial` fails with GCC 12.3.0 (no problem with GCC 9.x 10.x 11.x 13.x) HOT 1
- folly::ConcurrentHashMap crashes under high contention HOT 1
- [macOS] `AsyncFdSocket.h: error: 'reinterpret_cast<char*>(15)' is not a constant expression` and other related build errors
- error C2382: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::_Eos': redefinition; different exception specifications HOT 7
- undefined reference to `folly::f14::detail::F14LinkCheck HOT 1
- ‘scm_timestamping’ does not name a type
- Is ConcurrentHashMap read lock-free? HOT 2
- Folly fails to build on Windows 11 with build.bat and getdeps.py scripts.
- how to enable folly with sse4.2
- Integrate with google/oss-fuzz for continuous fuzz testing?
- A question about coro::Mutex implementation
- [powerpc] Some build errors and test results: issues to be addressed – threading, endianness HOT 22
- Build failure with Fedora 40's GCC 14.0.1
- Eroor
- Sweep: write an app with main.py
- [MSVC] Folly failed due to error C7555: use of designated initializers requires at least '/std:c++20' HOT 1
- EventBaseAtomicNotificationQueue - Check Failed
- Broken check for std::ranges?
- v2024.02.19 branch FTBFS / glog was not included correctly
- loadUnaligned and strict aliasing
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 folly.