Conversion function template with a deduced return type

83 views Asked by At

According to the standard class.conv.fct#6:

A conversion function template shall not have a deduced return type.

This prohibition appeared after CWG1878, which was resolved almost 10 years ago.

Still, the latest releases of GCC 13, Clang 17 and MSVC 19.38 do accept conversion function template in certain circumstances, e.g.:

struct A {
    template<class=void>
    constexpr operator auto() const { return 1; }
};

constexpr int f() {
    return A{}.operator auto();
}

static_assert( f() == 1 );

Online demo: https://godbolt.org/z/addcfxh8o

The motivation of CWG1878 was that it "presents difficulties for some implementations". But since we see that at least 3 major implementations successfully supported conversion function template, is it still a valid justification for the prohibition? Probably there is a case that shows incompatibility of conversion function template with some other language feature?

0

There are 0 answers