1 // Test for narrowing diagnostics
2 // { dg-do compile { target c++11 } }
3 
4 #include <initializer_list>
5 
6 struct A { int i; int j; };
7 A a2 { 1.2 }; // { dg-error "narrowing" }
8 A a1 { 1, 2 }; // aggregate initialization
9 struct B {
10   B(std::initializer_list<int>);
11 };
12 B b1 { 1, 2 }; // creates initializer_list<int> and calls constructor
13 B b2 { 1, 2.0 }; // { dg-error "narrowing" }
14 struct C {
15   C(int i, double j);
16 };
17 C c1 = { 1, 2.2 }; // calls constructor with arguments (1, 2.2)
18 C c2 = { 1.1, 2 }; // { dg-error "narrowing" }
19 
20 int j { 1 }; // initialize to 1
21 int k {}; // initialize to 0
22 
23 // PR c++/36963
24 double d = 1.1;
25 float fa[] = { d, 1.1 };      // { dg-error "narrowing conversion of 'd'" }
26 constexpr double d2 = 1.1;
27 float fa2[] = { d2, 1.1 };
28 
29 // PR c++/49577
30 unsigned u{ -1 };		// { dg-error "narrowing" }
31 char c = char{ u };		// { dg-error "narrowing" }
32 
33 // PR c++/50011
34 short unsigned su;
35 int i { su };
36