auto as a conversion-type-id
Section [dcl.spec.auto.general]
Jim X

Created on 2021-03-10.00:00:00 last changed 8 months ago


Date: 2021-03-10.00:00:00

Given the example,

  struct A{
   operator auto(){
     return 0;
  int main(){
    A a;
    a.operator auto(); // #1
    a.operator int();  // #2

there is implementation divergence regarding which, if either, of the calls is well-formed. MSVC and clang reject #2, g++ rejects #1, and EDG rejects both.

According to [dcl.spec.auto.general] paragraph 6:

A program that uses a placeholder type in a context not explicitly allowed in [dcl.spec.auto] is ill-formed.

The use of auto as a conversion-type-id in a function call is not mentioned in that section; however, the section is dealing with declarative contexts rather than expressions, so it's not clear how much weight that observation should carry.

Date User Action Args
2021-03-10 00:00:00admincreate