GithubHelp home page GithubHelp logo

Comments (7)

derekmauro avatar derekmauro commented on September 26, 2024

The example code provided contains syntax errors. Sure, I could try to fix them, but then I would just be guessing what your code actually says and possibly hiding the error. Please provide a working reproduction.

from abseil-cpp.

JuniorHsu avatar JuniorHsu commented on September 26, 2024

The example code provided contains syntax errors. Sure, I could try to fix them, but then I would just be guessing what your code actually says and possibly hiding the error. Please provide a working reproduction.

const StringViewMap& replacements() const {

remove second const should work, sorry i try to have a minimal viable test but didn't compile again

I modify the initial STR too

from abseil-cpp.

derekmauro avatar derekmauro commented on September 26, 2024

I will not look at this until I have a complete reproduction.

from abseil-cpp.

JuniorHsu avatar JuniorHsu commented on September 26, 2024

I'll try to have a unit test

from abseil-cpp.

JuniorHsu avatar JuniorHsu commented on September 26, 2024

it's reproducible in my macOS from this commit
JuniorHsu@432bd53

~/code/abseil-cpp $ bazel test --sandbox_debug -c dbg  --test_output=streamed --verbose_failures --cxxopt=-std=c++20 absl/container:flat_hash_map_test --test_filter=FlatHashMap.EmptyStringViewMap
WARNING: Streamed test output requested. All tests will be run locally, without sharding, one at a time
INFO: Analyzed target //absl/container:flat_hash_map_test (0 packages loaded, 3 targets configured).
Running main() from gmock_main.cc
Note: Google Test filter = FlatHashMap.EmptyStringViewMap
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from FlatHashMap
[ RUN      ] FlatHashMap.EmptyStringViewMap
absl/container/flat_hash_map_test.cc:91: Failure
Expected equality of these values:
  r.size()
    Which is: 1
  2

[  FAILED  ] FlatHashMap.EmptyStringViewMap (0 ms)
[----------] 1 test from FlatHashMap (0 ms total)

from abseil-cpp.

derekmauro avatar derekmauro commented on September 26, 2024

Thank you for the reproduction.

This isn't an absl::flat_hash_map issue. std::unordered_map demonstrates the same behavior.

If you replace new type{__VA_ARGS__} with new type(__VA_ARGS__) in CONSTRUCT_ON_FIRST_USE then it will work, but I don't think you want to do that, because it will change the meaning of other code.

Basically this is a more complicated form of

std::vector<int> v(5, 0);  // Vector v holds 5 zeros -> {0, 0, 0, 0, 0}
std::vector<int> v{5, 0};  // Vector v holds a 5 and a 0 -> {5, 0}

C++20 added a new string_view constructor which is why you are seeing this issue in C++20 only. A different constructor is getting called.

My only advice is not to use CONSTRUCT_ON_FIRST_USE at all. absl::NoDestructor might be helpful here.
See also https://abseil.io/tips/88.

from abseil-cpp.

JuniorHsu avatar JuniorHsu commented on September 26, 2024

Thanks for digging on this. I filed envoyproxy/envoy#33804
Could be a design defect on c++ 20 if we could reproduce in std::unordered_map

from abseil-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.