blob: 68acbdd4eaa3a77c142e53b1bdfe0e5f3d8c8a45 [file] [log] [blame]
John McCallb7f4ffe2010-08-12 21:44:57 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s
2
3// Simple casts.
4void test0(char *P) {
5 char *a; short *b; int *c;
6
7 a = (char*) P;
8 a = static_cast<char*>(P);
9 a = reinterpret_cast<char*>(P);
10 typedef char *CharPtr;
11 a = CharPtr(P);
12
13 b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}}
John McCall35a38d92010-08-19 01:19:08 +000014 b = reinterpret_cast<short*>(P);
John McCallb7f4ffe2010-08-12 21:44:57 +000015 typedef short *ShortPtr;
16 b = ShortPtr(P); // expected-warning {{cast from 'char *' to 'ShortPtr' (aka 'short *') increases required alignment from 1 to 2}}
17
18 c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}}
John McCall35a38d92010-08-19 01:19:08 +000019 c = reinterpret_cast<int*>(P);
John McCallb7f4ffe2010-08-12 21:44:57 +000020 typedef int *IntPtr;
21 c = IntPtr(P); // expected-warning {{cast from 'char *' to 'IntPtr' (aka 'int *') increases required alignment from 1 to 4}}
22}
23
24// Casts from void* are a special case.
25void test1(void *P) {
26 char *a; short *b; int *c;
27
28 a = (char*) P;
29 a = static_cast<char*>(P);
30 a = reinterpret_cast<char*>(P);
31 typedef char *CharPtr;
32 a = CharPtr(P);
33
34 b = (short*) P;
35 b = static_cast<short*>(P);
36 b = reinterpret_cast<short*>(P);
37 typedef short *ShortPtr;
38 b = ShortPtr(P);
39
40 c = (int*) P;
41 c = static_cast<int*>(P);
42 c = reinterpret_cast<int*>(P);
43 typedef int *IntPtr;
44 c = IntPtr(P);
45}