René's URL Explorer Experiment


Title: Correctness bugs: set::min()/max() ignore comparator; non-const set::operator[] does not compile · Issue #28 · jkalias/functional_cpp · GitHub

Open Graph Title: Correctness bugs: set::min()/max() ignore comparator; non-const set::operator[] does not compile · Issue #28 · jkalias/functional_cpp

X Title: Correctness bugs: set::min()/max() ignore comparator; non-const set::operator[] does not compile · Issue #28 · jkalias/functional_cpp

Description: Summary Two correctness defects in include/set.h. Both are currently masked by the test suite (one via a compiler-conditional expectation, one because the buggy overload is never instantiated) rather than fixed. 1. set::min() / max() ign...

Open Graph Description: Summary Two correctness defects in include/set.h. Both are currently masked by the test suite (one via a compiler-conditional expectation, one because the buggy overload is never instantiated) rath...

X Description: Summary Two correctness defects in include/set.h. Both are currently masked by the test suite (one via a compiler-conditional expectation, one because the buggy overload is never instantiated) rath...

Opengraph URL: https://github.com/jkalias/functional_cpp/issues/28

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Correctness bugs: set::min()/max() ignore comparator; non-const set::operator[] does not compile","articleBody":"## Summary\n\nTwo correctness defects in `include/set.h`. Both are currently masked by the test suite (one via a compiler-conditional expectation, one because the buggy overload is never instantiated) rather than fixed.\n\n---\n\n### 1. `set::min()` / `max()` ignore the set's comparator (and are O(n))\n\n**Location:** `include/set.h:607-635`\n\n```cpp\n[[nodiscard]] fcpp::optional_t\u003cTKey> min() const\n{\n    const auto& it = std::min_element(begin(), end());\n    if (it != end()) {\n        return *it;\n    }\n    return fcpp::optional_t\u003cTKey>();\n}\n```\n\n`std::min_element` / `std::max_element` compare elements with `operator\u003c` on `TKey`, **not** with the set's `TCompare`.\n\n**Consequences**\n- **Wrong result** for any set instantiated with a custom comparator. The set is stored ordered by `TCompare`, but `min()`/`max()` re-rank by `operator\u003c`, so they can return the wrong element.\n- **Fails to compile** for key types that provide `TCompare` but not `operator\u003c`.\n- **O(n)** where it should be **O(1)**: a `std::set` is already ordered, so the minimum is `*begin()` and the maximum is `*std::prev(end())`.\n\n**Evidence — the test papers over this instead of fixing it** (`tests/set_test.cc:289`):\n\n```cpp\nTEST(SetTest, MinCustomType)\n{\n    const set\u003cperson, person_comparator> persons({\n        person(15, \"Jake\"), person(18, \"Jannet\"),\n        person(25, \"Kate\"), person(62, \"Bob\")\n    });\n    const auto minimum = persons.min();\n#if defined(__clang__)\n    EXPECT_EQ(person(18, \"Jannet\"), minimum.value());\n#else\n    EXPECT_EQ(person(62, \"Bob\"), minimum.value());   // different answer per compiler\n#endif\n}\n```\n\nThe fact that the expected value differs between clang and gcc is a direct symptom of the bug: the answer depends on `operator\u003c` and iteration order rather than the set's actual ordering.\n\n**Suggested fix**\n\n```cpp\n[[nodiscard]] fcpp::optional_t\u003cTKey> min() const\n{\n    if (m_set.empty()) {\n        return fcpp::optional_t\u003cTKey>();\n    }\n    return *begin();              // ordered by TCompare, O(1)\n}\n\n[[nodiscard]] fcpp::optional_t\u003cTKey> max() const\n{\n    if (m_set.empty()) {\n        return fcpp::optional_t\u003cTKey>();\n    }\n    return *std::prev(end());     // O(1)\n}\n```\n\nThis is deterministic, respects the custom comparator, is O(1), and allows the `#if defined(__clang__)` branch in `SetTest.MinCustomType` (and the analogous max test) to be removed.\n\n---\n\n### 2. Non-const `set::operator[]` does not compile\n\n**Location:** `include/set.h:1102-1116`\n\n```cpp\nTKey operator[](size_t index)\n{\n    assert_smaller_size(index);\n#ifdef CPP17_AVAILABLE\n    auto it = std::advance(begin(), index);   // std::advance returns void\n    return *it;\n#else\n    ...\n#endif\n}\n```\n\n`std::advance` returns `void`, so `auto it = std::advance(...)` is ill-formed. The **const** overload (`set.h:1121-1136`) does it correctly:\n\n```cpp\nauto it = begin();\nstd::advance(it, index);\nreturn *it;\n```\n\n**Why it's currently hidden:** every call site in the tests uses `operator[]` on a `const set&` (e.g. `test_contents(const set\u003cint>& set)` at `tests/set_test.cc:37`), so the non-const overload is never instantiated. Any use such as:\n\n```cpp\nfcpp::set\u003cint> s({1, 2, 3});\nauto x = s[0];   // selects the non-const overload -> compile error\n```\n\nwould fail to build under C++17.\n\n**Suggested fix:** mirror the const overload:\n\n```cpp\nTKey operator[](size_t index)\n{\n    assert_smaller_size(index);\n    auto it = begin();\n    std::advance(it, index);   // works for both C++11 and C++17 paths\n    return *it;\n}\n```\n\nA regression test that subscripts a **non-const** set would prevent this from regressing.\n","author":{"url":"https://github.com/jkalias","@type":"Person","name":"jkalias"},"datePublished":"2026-06-11T15:11:46Z","url":"https://github.com/jkalias/functional_cpp/issues/28"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ec7eb6c1-f250-43c9-b97b-beadaf8437db
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id94C0:3ABDFB:49E097:655478:6B04704A
html-safe-nonce59ff48090f466a1b35a62ed0113150930f4f1dc9b8252ff4a7c77387564909f1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEMwOjNBQkRGQjo0OUUwOTc6NjU1NDc4OjZCMDQ3MDRBIiwidmlzaXRvcl9pZCI6IjM3ODE2NzgxODcyMDE5ODI1MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaca2cca087492cd51fe712bc35ed730080d9cb2784e5fdb741ae853eeaf43d87c8
hovercard-subject-tagissue:4641795730
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/jkalias/functional_cpp/28/issue_layout
twitter:imagehttps://opengraph.githubassets.com/860309cf121f5bd192eefd912f963176b187620df3ea227b602069b6213985fd/jkalias/functional_cpp/issues/28
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/860309cf121f5bd192eefd912f963176b187620df3ea227b602069b6213985fd/jkalias/functional_cpp/issues/28
og:image:altSummary Two correctness defects in include/set.h. Both are currently masked by the test suite (one via a compiler-conditional expectation, one because the buggy overload is never instantiated) rath...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejkalias
hostnamegithub.com
expected-hostnamegithub.com
Noneae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f
turbo-cache-controlno-preview
go-importgithub.com/jkalias/functional_cpp git https://github.com/jkalias/functional_cpp.git
octolytics-dimension-user_id942804
octolytics-dimension-user_loginjkalias
octolytics-dimension-repository_id387602376
octolytics-dimension-repository_nwojkalias/functional_cpp
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id387602376
octolytics-dimension-repository_network_root_nwojkalias/functional_cpp
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecfb5f24c6e01d85f70804652a5107e5cac03a161
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/jkalias/functional_cpp/issues/28#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjkalias%2Ffunctional_cpp%2Fissues%2F28
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjkalias%2Ffunctional_cpp%2Fissues%2F28
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=jkalias%2Ffunctional_cpp
Reloadhttps://github.com/jkalias/functional_cpp/issues/28
Reloadhttps://github.com/jkalias/functional_cpp/issues/28
Reloadhttps://github.com/jkalias/functional_cpp/issues/28
jkaliashttps://github.com/jkalias
functional_cpphttps://github.com/jkalias/functional_cpp
Codehttps://github.com/jkalias/functional_cpp
Issueshttps://github.com/jkalias/functional_cpp/issues
Pull requestshttps://github.com/jkalias/functional_cpp/pulls
Actionshttps://github.com/jkalias/functional_cpp/actions
Projectshttps://github.com/jkalias/functional_cpp/projects
Security and qualityhttps://github.com/jkalias/functional_cpp/security
Insightshttps://github.com/jkalias/functional_cpp/pulse
https://github.com/jkalias/functional_cpp
New issuehttps://github.com/login?return_to=https://github.com/jkalias/functional_cpp/issues/28
New issuehttps://github.com/login?return_to=https://github.com/jkalias/functional_cpp/issues/28
#32https://github.com/jkalias/functional_cpp/pull/32
Correctness bugs: set::min()/max() ignore comparator; non-const set::operator[] does not compilehttps://github.com/jkalias/functional_cpp/issues/28#top
#32https://github.com/jkalias/functional_cpp/pull/32
https://github.com/jkalias
jkaliashttps://github.com/jkalias
on Jun 11, 2026https://github.com/jkalias/functional_cpp/issues/28#issue-4641795730
jkaliashttps://github.com/jkalias
on Jun 13, 2026https://github.com/jkalias/functional_cpp/issues/28#event-26713276852
Fix set::min()/max() comparator bug and non-const operator[] (#32)https://github.com/jkalias/functional_cpp/commit/0ebec4cdef48b9a47ea7cc534d6841fc8fd27b46
#32https://github.com/jkalias/functional_cpp/pull/32
0ebec4chttps://github.com/jkalias/functional_cpp/commit/0ebec4cdef48b9a47ea7cc534d6841fc8fd27b46
jkaliashttps://github.com/jkalias
completedhttps://github.com/jkalias/functional_cpp/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#32https://github.com/jkalias/functional_cpp/pull/32
on Jun 13, 2026https://github.com/jkalias/functional_cpp/issues/28#event-26713276861
Sign up for freehttps://github.com/signup?return_to=https://github.com/jkalias/functional_cpp/issues/28
Sign in to commenthttps://github.com/login?return_to=https://github.com/jkalias/functional_cpp/issues/28
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.