Title
Overload resolution of conversion operator templates with built-in types
Status
open
Section
12.5 [over.built]
Submitter
Steve Clamage

Created on 2009-08-19.00:00:00 last changed 178 months ago

Messages

Date: 2010-08-23.00:00:00

Consider the following example:

    struct NullClass {
        template<typename T> operator T () { return 0 ; }
    };

    int main() {
        NullClass n;
        n==5;        // #1
        return 0;
    }

The comparison at #1 is, according to the current Standard, ambiguous. According to 12.5 [over.built] paragraph 12, the candidates for operator==(L, R) include functions “for every pair of promoted arithmetic types,” so L could be either int or long, and the conversion operator template will provide an exact match for either.

Some implementations unambiguously choose the int candidate. Perhaps the overload resolution rules could be tweaked to prefer candidates in which L and R are the same type?

(See also issue 545.)

History
Date User Action Args
2009-08-19 00:00:00admincreate