1*e45e091bSCongcong Cai // RUN: %check_clang_tidy %s bugprone-narrowing-conversions %t \
2*e45e091bSCongcong Cai // RUN: -- -- -target x86_64-unknown-linux -m32
3*e45e091bSCongcong Cai 
4*e45e091bSCongcong Cai static_assert(sizeof(int) * 8 == 32, "int is 32-bits");
5*e45e091bSCongcong Cai static_assert(sizeof(long) * 8 == 32, "long is 32-bits");
6*e45e091bSCongcong Cai static_assert(sizeof(long long) * 8 == 64, "long long is 64-bits");
7*e45e091bSCongcong Cai 
8*e45e091bSCongcong Cai void narrow_integer_to_signed_integer_is_not_ok() {
9*e45e091bSCongcong Cai   int i;        // i.e. int32_t
10*e45e091bSCongcong Cai   long l;       // i.e. int32_t
11*e45e091bSCongcong Cai   long long ll; // i.e. int64_t
12*e45e091bSCongcong Cai 
13*e45e091bSCongcong Cai   unsigned int ui;        // i.e. uint32_t
14*e45e091bSCongcong Cai   unsigned long ul;       // i.e. uint32_t
15*e45e091bSCongcong Cai   unsigned long long ull; // i.e. uint64_t
16*e45e091bSCongcong Cai 
17*e45e091bSCongcong Cai   i = l;  // int and long are the same type.
18*e45e091bSCongcong Cai   i = ll; // int64_t does not fit in an int32_t
19*e45e091bSCongcong Cai   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions]
20*e45e091bSCongcong Cai   ll = ul;  // uint32_t fits into int64_t
21*e45e091bSCongcong Cai   ll = ull; // uint64_t does not fit in an int64_t
22*e45e091bSCongcong Cai   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned long long' to signed type 'long long' is implementation-defined [bugprone-narrowing-conversions]
23*e45e091bSCongcong Cai }
24