Skip to content

spell out overload resolution #292

@pseyfert

Description

@pseyfert

(triggered by this SO question)

I have noticed that while I was successful using cppinsights to look up what overload resolution a compiler picks on free standing functions example this does only work when implicit casts are involved. In a minimalized version of the above SO question here I see no cast that turns 0 to double*.
Artificially adding local variables (attempt) doesn't help spelling out the overload resolution either.

Long story short, I think it would be nice to see which overload resolution the compiler picked.

I see github detects my draft is similar to #249. I'm not sure how a printout could look. If I as a code author wanted to be explicit about which overload I want to pick, I'd probably add a comment of the intended signature

class H
{
  public: 
  H(const char *, int, double, double);
  H(const char *, int, double *);
  ~H();
};

H foo()
{
  // H(const char*, int, double*)
  return H{"hai", 4, 0};
}

though that might be messy once composed function calls are involved f(g(h(x))).
Matching how I used cppinsights so far for overload resolution, the following might also be usable

return H{static_cast<const char *>("hai"), static_cast<int>(4), static_cast<double *>(0)};

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions