Repository navigation
operator[] overloads for const char* keys - #26
Merged
jeandet merged 1 commit intoNov 19, 2026
Merged
Conversation
With the implicit operator T&() conversion, a Dict with a long leaf (std::int64_t / std::ptrdiff_t on LP64) makes dict["key"] ambiguous on clang between the member operator[](std::string const&) and the built-in "key"[dict]. An exact match overload for const char* resolves it.
jeandet
merged commit Nov 19, 2026
46e6deb
into
LaboratoryOfPlasmaPhysics:master
2 of 3 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the implicit
operator T&()conversion, aDictwith alongleaf (std::int64_t/std::ptrdiff_ton LP64) makesdict["key"]ambiguous on clang:operator[](std::string const&): exact ondict, user-defined conversion on"key""key"[dict]i.e.operator[](ptrdiff_t, char const*): user-defined conversion ondict(viaoperator long&()), exact on"key"GCC accepts it (it skips conversion templates when forming built-in candidates), clang rejects it. Seen in cppconfig CI with a
Dict<std::int64_t, ...>.Adding
operator[](const char*)(and const) gives string literals an exact match so the member always wins, while keeping the implicit conversion (T x = dict[...]).Adds a regression test, which fails to compile on clang without the fix.