John McCall | ecda6fb | 2010-07-13 06:26:23 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion -verify %s |
| 2 | |
| 3 | typedef signed char int8_t; |
| 4 | typedef signed short int16_t; |
| 5 | typedef signed int int32_t; |
| 6 | typedef signed long int64_t; |
| 7 | |
| 8 | typedef unsigned char uint8_t; |
| 9 | typedef unsigned short uint16_t; |
| 10 | typedef unsigned int uint32_t; |
| 11 | typedef unsigned long uint64_t; |
| 12 | |
| 13 | // <rdar://problem/7909130> |
| 14 | namespace test0 { |
| 15 | int32_t test1_positive(char *I, char *E) { |
| 16 | return (E - I); // expected-warning {{implicit conversion loses integer precision}} |
| 17 | } |
| 18 | |
| 19 | int32_t test1_negative(char *I, char *E) { |
| 20 | return static_cast<int32_t>(E - I); |
| 21 | } |
| 22 | |
| 23 | uint32_t test2_positive(uint64_t x) { |
| 24 | return x; // expected-warning {{implicit conversion loses integer precision}} |
| 25 | } |
| 26 | |
| 27 | uint32_t test2_negative(uint64_t x) { |
| 28 | return (uint32_t) x; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | namespace test1 { |
| 33 | uint64_t test1(int x, unsigned y) { |
| 34 | return sizeof(x == y); |
| 35 | } |
| 36 | |
| 37 | uint64_t test2(int x, unsigned y) { |
| 38 | return __alignof(x == y); |
| 39 | } |
| 40 | |
| 41 | void * const foo(); |
| 42 | bool test2(void *p) { |
| 43 | return p == foo(); |
| 44 | } |
| 45 | } |
John McCall | 15d7d12 | 2010-11-11 03:21:53 +0000 | [diff] [blame] | 46 | |
| 47 | namespace test2 { |
| 48 | struct A { |
| 49 | unsigned int x : 2; |
| 50 | A() : x(10) {} // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} |
| 51 | }; |
| 52 | } |