Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / diagnostic / explicit.C
blob122accb86c159550b1a5ce846ed86c54b0a7542a
1 // { dg-do compile { target c++11 } }
3 struct A {
4   long int l;
5 };
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" }
17 double
18 f (char)
20   return S{2}; // { dg-error "cannot convert .S. to .double. in return" }
23 void
24 g ()
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" }