Skip to content

[over.match.funcs] Conversion function template candidates #699

Open
@randomnetcat

Description

@randomnetcat

Full name of submitter: Janet Cobb

Reference (section label): [over.match.funcs]

Issue description:

Consider the following code:

struct S {
    template<int = 0>
    operator int&&() { throw 0; }
};

int i = S();

The four common compilers agree that this is well-formed.

Initialization is done pursuant to [dcl.init.general]/16.7. As far as I can tell, the only candidates are those defined by [over.match.funcs.general]/7. Since the object being initialized is of type int, the first sentence only introduces candidates that would be found by operator int, which does not include the conversion function template. The remainder of the paragraph explicitly excludes conversion function templates (regardless of the "permissible types"). Thus, there do not appear to be any candidates for the conversion.

Since all common implementations think operator int&& is a candidate, I'm filing this defect report rather than a bug report with each implementation, in the hopes that this is an issue with the wording.

Here are some other interesting cases with templates that do not appear to be candidates under the current wording:

Suggested resolution:

Exactly how this should be resolved is unclear. One possibility would be to modify the first sentence of [over.match.funcs.general]/7 to include cv T, cv T&, and cv T&& just like the second portion of the paragraph does. This would address the initial example, but not any of the other cases that implementations think are well-formed.

This suggests that a potential resolution would be to explicitly include types U that can be converted to T by some specific subset of conversions (similarly to, e.g., [over.match.conv]. Another possible resolution is that the status quo is correct and that all of the implementations are wrong, although implementing that seems likely to break code and perhaps counterintuitive (since, to me at least, it seems like the original example should be well-formed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions