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