1 // Test for explicit conversion ops from N2437. 2 // { dg-do compile { target c++11 } } 3 4 class U; class V; 5 class T 6 { 7 public: 8 T( U const & ); 9 //implicit converting ctor 10 explicit T( V const & ); 11 // explicit ctor 12 }; 13 class U 14 { 15 }; 16 class V 17 { 18 }; 19 class W 20 { 21 public: 22 operator T() const; 23 }; 24 class X 25 { 26 public: 27 explicit operator T() const; // theoretical 28 }; main()29int main() 30 { 31 U u; V v; W w; X x; 32 // Direct initialization: 33 T t1( u ); 34 T t2( v ); 35 T t3( w ); 36 T t4( x ); 37 // Copy initialization: 38 T t5 = u; 39 T t6 = v; // { dg-error "" } 40 T t7 = w; 41 T t8 = x; // { dg-error "" } 42 // Cast notation: 43 T t9 = (T) u; 44 T t10 = (T) v; 45 T t11 = (T) w; 46 T t12 = (T) x; 47 // Static cast: 48 T t13 = static_cast<T>( u ); 49 T t14 = static_cast<T>( v ); 50 T t15 = static_cast<T>( w ); 51 T t16 = static_cast<T>( x ); 52 // Function-style cast: 53 T t17 = T( u ); 54 T t18 = T( v ); 55 T t19 = T( w ); 56 T t20 = T( x ); 57 return 0; 58 } 59