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)
- <limits> file not found HOT 1
- Link error when using optimization flag -O2
- Maybe some problems with glog? Can't make folly HOT 1
- 2024.06.10.00: error: use of undeclared identifier 'cxxabi_with_cxa_exception' HOT 4
- build failed by following "Build Notes" on Ubuntu 24.04 LTS HOT 1
- label:question ”if the ThreadEntry already exists but pthread_getspecific returns NULL“. How could it happen? HOT 3
- use ParkingLot to construct WaitableMutex will crash
- /usr/include/c++/v1/cxxabi.h:182:8: error: redefinition of '__cxa_eh_globals' HOT 2
- What is the difference between fiber and c++20 coroutine? HOT 1
- Tests fail to compile
- Building with Buck2 HOT 5
- GenPkgConfig.cmake: file(GENERATE) failed with $<COMPILE_LANGUAGE> in fmt 11.0.0 MSVC
- linux : arm64 : undefined reference to `__folly_memcpy_aarch64'
- TLS Renegotiation
- build from source failed on win11 ```subprocess.CalledProcessError: Command '['git', 'apply', '--ignore-space-change', 'D:\\code\\folly\\build\\fbcode_builder\\patches\\boost_comparator_operator_fix.patch']' returned non-zero exit status 128.``` HOT 1
- Build fails on macOS 10.15: `ThreadLocal.h: error: no matching constructor for initialization of 'std::function<LocalRefCount ()>'` HOT 4
- coredump if link with tcmalloc HOT 2
- link static to jemalloc or tcmalloc will cause coredump HOT 3
- List index out of range: build error
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.