Home > front end >  What's the difference between an explicit call and an implicit call of the conversion function?
What's the difference between an explicit call and an implicit call of the conversion function?

Time:04-08

Consider this example:

struct A{
    template<class T>
    operator T();  // #1
};
struct B:A{
    template<class U>
    operator U&&();  // #2
};
int main(){
  B  b;
  int a = b;  // #3
  b.operator int();  // #4
}

According to [class.member.lookup] p7

If N is a non-dependent conversion-function-id, conversion function templates that are members of T are considered. For each such template F, the lookup set S(t,T) is constructed, considering a function template declaration to have the name t only if it corresponds to a declaration of F ([basic.scope.scope]). The members of the declaration set of each such lookup set, which shall not be an invalid set, are included in the result.

#1 and #2 are both included in the lookup result regardless of what the conversion-function-ids are in #3 and #4. The diagnosis for #3 is what we expect, in other words, both #1 and #2 are candidates and they are indistinguishable.

However, it seems that implementations only consider #2 as the unique candidate when processing #4. As said above, the candidate set should be the same for either #3 or #4. Do I omit some other rules that cause the difference? Or, Is it a bug in implementations?

CodePudding user response:

Implementations just haven’t caught up to the new(ly clarified) rules, which had to be largely invented in 2020 since no published standard version has ever described lookup for conversion function templates in any sensible way.

  • Related