Skip to content

[over.over] Add example for successful placeholder type deduction with overload set #945

Description

@t3nsor

Full name of submitter: Brian Bi

Issue description: CWG2918 contained the following example:

  template<bool B> struct X {
    void f(short) requires B;
    void f(short);
    template<typename> void g(short) requires B;
    template<typename> void g(short);
  };
  void test(X<true> x) {
    auto r = &X<true>::f;       // #5
    auto s = &X<true>::g<int>;  // #6
  }

The intent is that #5 is valid. The wording added to accomplish this intent was, in [over.over]/1:

If the target type contains a placeholder type, placeholder type deduction is performed ([dcl.type.auto.deduct]), and the remainder of this subclause uses the target type so deduced.

This sentence is difficult to understand, since it is not immediately obvious how placeholder type deduction can succeed when the selected member of the overload set is not yet known.

Suggested resolution: Edit Example 3 in [over.over]/6 as follows:

template<bool B> struct X {
+ void e(int) requires B;
+ void e(int);
  void f(short) requires B;
  void f(long);
  template<typename> void g(short) requires B;
  template<typename> void g(long);
};
void test() {
+ auto ep = &X<true>::e;        // OK, placeholder type deduction succeeds, then most partial-ordering-constrained overload is selected
  &X<true>::f;                  // error: ambiguous; constraints are not considered
  &X<true>::g<int>;             // error: ambiguous; constraints are not considered
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions