Converting default arguments not considered when choosing overload?

I tried to write a direct solution to this question: array decay to pointer and overload resolution

Obviously, in the original, both overloads have the same conversion power (exact match), so not the template is preferred. Indeed, if I change another template, the call becomes ambiguous:

struct stg
{
    template<typename T = void>
    stg(const char* const& c_str, T* = 0);

    template<int N>
    stg(const char (&str) [N]);
};

So, I wanted to introduce a custom transformation that would be strictly worse than the exact match of the second overload.

struct stg
{
    template<typename> struct cvt { operator int() { return 0;} };

    template<typename T = void>
    stg(const char* const& c_str, int = cvt<T>());

    template<int N>
    stg(const char (&str) [N]);
};

But g ++ says this is still ambiguous . Why doesn't the custom conversion in the default argument affect the overload rating?

+3
1

[over.match.viable]/2 (from > n3797, github 5f7cb4)

-, , .

  • m , -, m .

  • -, m , , (8.3.5). , , " " (13.3.3.1.3).

  • -, m , , (m + 1) -st (8.3.6). , m .

[ ]

+4

All Articles