| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
|
| 3 |
struct A { |
| 4 |
long int l; |
| 5 |
}; |
| 6 |
|
| 7 |
struct S { |
| 8 |
explicit S(int) { } |
| 9 |
explicit operator bool() const { return true; } // { dg-message "explicit conversion function was not considered" } |
| 10 |
explicit operator int() const { return 42; } // { dg-message "explicit conversion function was not considered" } |
| 11 |
explicit operator char() const { return 42; } // { dg-message "explicit conversion function was not considered" } |
| 12 |
explicit operator double() const { return 42.; } // { dg-message "explicit conversion function was not considered" } |
| 13 |
explicit operator float() const { return 42.; } // { dg-message "explicit conversion function was not considered" } |
| 14 |
explicit operator long() const { return 42.; } // { dg-message "explicit conversion function was not considered" } |
| 15 |
}; |
| 16 |
|
| 17 |
double |
| 18 |
f (char) |
| 19 |
{ |
| 20 |
return S{2}; // { dg-error "cannot convert .S. to .double. in return" } |
| 21 |
} |
| 22 |
|
| 23 |
void |
| 24 |
g () |
| 25 |
{ |
| 26 |
S s = {1}; // { dg-error "would use explicit constructor" } |
| 27 |
bool b = S{1}; // { dg-error "cannot convert .S. to .bool. in initialization" } |
| 28 |
int i; |
| 29 |
i = S{2}; // { dg-error "cannot convert .S. to .int. in assignment" } |
| 30 |
f (S{3}); // { dg-error "cannot convert .S. to .char." } |
| 31 |
A a{ S{4} }; // { dg-error "cannot convert .S. to .long int. in initialization" } |
| 32 |
float arr[1] = { S{5} }; // { dg-error "cannot convert .S. to .float. in initialization" } |
| 33 |
} |