http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55101



             Bug #: 55101

           Summary: Invalid implicit conversion in initialization when

                    source type is a template argument type

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: cassio.n...@gmail.com





Calling f(b) below implies an implicit call to an explicit conversion operator.

This is fine with for gcc 4.8.0 but illegal for clang 3.1 and 3.2 (trunk).

Notice that gcc complains (as it should) in other similar circumstances.



struct A { };



struct B {

  explicit operator int() const { return 1; }

  explicit operator A() const { return A(); }

};



template <typename T> void f(T b) { int x = b; }

template <typename T> void g(T b) {   A y = b; }



int main() {



  B b;



  //int x = b; // Error: cannot convert 'B' to 'int' in initialization

  f(b);        // OK for gcc 4.8.0, despite that 'int x = b;' occurs inside f

               // Error for clang 3.1 and 3.2.



  //A y = b;   // Error: conversion from 'B' to non-scalar type 'A' requested

  //g(b);      // Error: conversion from 'B' to non-scalar type 'A' requested

}

Reply via email to