https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126730

            Bug ID: 126730
           Summary: `std::filesystem::hash_value` returns different hash
                    value for paths that compare equal
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 121539739 at qq dot com
  Target Milestone: ---

[fs.path.nonmember] says:

> `size_t hash_value(const path& p) noexcept; `
>
>     *Returns*: A hash value for the path `p`. If for two paths, `p1 == p2` 
> then `hash_value(p1) == hash_value(p2)`.

```cpp
#include <cassert>
#include <filesystem>

namespace fs = std::filesystem;

int main() {
    fs::path a{ "/" }, b{ "//" }, c{ "///" };
    assert(a == b); // ok
    assert(b == c); // ok

    assert(fs::hash_value(a) == fs::hash_value(b)); // fail
    assert(fs::hash_value(b) == fs::hash_value(c)); // fail
}
```

`a`, `b` and `c` compare equal, but their `hash_value`s diverge.

libc++ and MS STL both agree these paths compare equal and both give equal
hashes.

detailed: https://godbolt.org/z/Gh66jnvzK

Reply via email to