cplusplus / nbballot

Handling of NB comments in response to ballots
14 stars 4 forks source link

CA-064 12.2.2.2.3 [over.call.object] Fix incorrect note #464

Closed wg21bot closed 1 year ago

wg21bot commented 1 year ago

Contrary to the note in the subject paragraph, overload resolution in selecting a surrogate call function can prefer a different conversion operator for the implicit conversion sequence because the conversion function from which the surrogate call function was derived is not the best viable function.

For example, noting that surrogate call functions are not generated from conversion function templates, the single surrogate call function derived from the (non-template) conversion function below is the sole candidate for the call; however, the specialization of the conversion function template is a better candidate for the implicit conversion sequence during overload resolution:

using ff = int (*)(int);
constexpr int ffimpl0(int x) {
  return x;
}
constexpr int ffimpl1(int x) {
  return x + 1;
}
struct A {
  template <typename T> constexpr operator T() const { return ffimpl0; }
  constexpr operator ff() const volatile { return ffimpl1; }
};
char x[A()(42.f)];
extern char x[43];

Remove from the note:

The conversion function from which the surrogate call function was derived will be used in the conversion sequence for that parameter since if converts the implied object argument to the appropriate function pointer or reference required by that first parameter.

jensmaurer commented 1 year ago

Before https://github.com/cplusplus/draft/pull/3625, the rule read

If such a surrogate call function is selected by overload resolution, the corresponding conversion function will be called to convert E to the appropriate function pointer or reference, and the function will then be invoked with the arguments of the call.

Note "corresponding", meaning the overload resolution choice of surrogate call function determines the conversion function to invoke (even if there is a better one available for the conversion).

After that change, the rule is in [over.call] and reads:

If a surrogate call function for a conversion function named operator conversion-type-id is selected, the expression is interpreted as

postfix-expression . operator conversion-type-id () ( expression-listopt )

which does permit a different overload resolution result for the conversion.

jensmaurer commented 1 year ago

CWG2649

jensmaurer commented 1 year ago

CWG 2022-11-08: Accepted.