Skip to content

Rules that convert between type parameters need overload resolution #700

Done

Description

@lucic71

f101 vector<T>::insert(pos, InputIt first, InputIt last) and similar rules (std::copy) build or assign a T from *first. C++ picks the conversion from the type of *first to T by overload resolution:

  • longs.insert(longs.end(), ratios.begin(), ratios.end()) with only Ratio::operator int() uses operator int(), then int -> long
  • ints.insert(ints.end(), ratios.begin(), ratios.end()) with operator short() and operator long() picks operator short, because short -> int is a promotion and beats the conversion long -> int

Rust traits can't express these: an intermediate type can't be chained, and overlapping impls can't be ranked. Not even nightly specialization can fully cover overload resolution.

I think the solution is to do overload resolution at runtime in libcc2rs. Each type generates a hidden table with all the needed information and the runtime overload resolution algorithm uses it to choose the right constructor.

Activity

  1. lucic71 commented on Dec 3, 2026

    @lucic71
    ContributorAuthor

    This is related to the ConstructibleFrom and ConvertibleTo work. Depends on #699

  2. added a commit that references this issue on Dec 4, 2026
    0d1207f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions