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 | |
Richard Trieu | 1838ca5 | 2011-05-29 19:59:02 +0000 | [diff] [blame] | 3 | #include <stddef.h> |
| 4 | |
John McCall | ecda6fb | 2010-07-13 06:26:23 +0000 | [diff] [blame] | 5 | typedef signed char int8_t; |
| 6 | typedef signed short int16_t; |
| 7 | typedef signed int int32_t; |
| 8 | typedef signed long int64_t; |
| 9 | |
| 10 | typedef unsigned char uint8_t; |
| 11 | typedef unsigned short uint16_t; |
| 12 | typedef unsigned int uint32_t; |
| 13 | typedef unsigned long uint64_t; |
| 14 | |
| 15 | // <rdar://problem/7909130> |
| 16 | namespace test0 { |
| 17 | int32_t test1_positive(char *I, char *E) { |
| 18 | return (E - I); // expected-warning {{implicit conversion loses integer precision}} |
| 19 | } |
| 20 | |
| 21 | int32_t test1_negative(char *I, char *E) { |
| 22 | return static_cast<int32_t>(E - I); |
| 23 | } |
| 24 | |
| 25 | uint32_t test2_positive(uint64_t x) { |
| 26 | return x; // expected-warning {{implicit conversion loses integer precision}} |
| 27 | } |
| 28 | |
| 29 | uint32_t test2_negative(uint64_t x) { |
| 30 | return (uint32_t) x; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | namespace test1 { |
| 35 | uint64_t test1(int x, unsigned y) { |
| 36 | return sizeof(x == y); |
| 37 | } |
| 38 | |
| 39 | uint64_t test2(int x, unsigned y) { |
| 40 | return __alignof(x == y); |
| 41 | } |
| 42 | |
| 43 | void * const foo(); |
| 44 | bool test2(void *p) { |
| 45 | return p == foo(); |
| 46 | } |
| 47 | } |
John McCall | 15d7d12 | 2010-11-11 03:21:53 +0000 | [diff] [blame] | 48 | |
| 49 | namespace test2 { |
| 50 | struct A { |
| 51 | unsigned int x : 2; |
| 52 | A() : x(10) {} // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} |
| 53 | }; |
| 54 | } |
Richard Trieu | 1838ca5 | 2011-05-29 19:59:02 +0000 | [diff] [blame] | 55 | |
| 56 | void test3() { |
| 57 | int a = NULL; // expected-warning {{implicit conversion of NULL constant to integer}} |
| 58 | int b; |
| 59 | b = NULL; // expected-warning {{implicit conversion of NULL constant to integer}} |
| 60 | int c = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to integer}} |
| 61 | int d; |
| 62 | d = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to integer}} |
| 63 | } |