blob: b069abc263f4aa129820a45c5078fe0a2b50aaa1 [file] [log] [blame]
John McCallecda6fb2010-07-13 06:26:23 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion -verify %s
2
Richard Trieu1838ca52011-05-29 19:59:02 +00003#include <stddef.h>
4
John McCallecda6fb2010-07-13 06:26:23 +00005typedef signed char int8_t;
6typedef signed short int16_t;
7typedef signed int int32_t;
8typedef signed long int64_t;
9
10typedef unsigned char uint8_t;
11typedef unsigned short uint16_t;
12typedef unsigned int uint32_t;
13typedef unsigned long uint64_t;
14
15// <rdar://problem/7909130>
16namespace 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
34namespace 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 McCall15d7d122010-11-11 03:21:53 +000048
49namespace 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 Trieu1838ca52011-05-29 19:59:02 +000055
56void 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}