1 // Test for narrowing diagnostics
2 // { dg-do compile { target c++11 } }
4 #include <initializer_list>
6 struct A { int i; int j; };
7 A a2 { 1.2 }; // { dg-error "narrowing" }
8 A a1 { 1, 2 }; // aggregate initialization
10 B(std::initializer_list<int>);
12 B b1 { 1, 2 }; // creates initializer_list<int> and calls constructor
13 B b2 { 1, 2.0 }; // { dg-error "narrowing" }
17 C c1 = { 1, 2.2 }; // calls constructor with arguments (1, 2.2)
18 C c2 = { 1.1, 2 }; // { dg-error "narrowing" }
20 int j { 1 }; // initialize to 1
21 int k {}; // initialize to 0
25 float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion of 'd'" }
26 constexpr double d2 = 1.1;
27 float fa2[] = { d2, 1.1 };
30 unsigned u{ -1 }; // { dg-error "narrowing" }
31 char c = char{ u }; // { dg-error "narrowing" }