1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc // Simple casts. test0(char * P)4*f4a2713aSLionel Sambucvoid test0(char *P) { 5*f4a2713aSLionel Sambuc char *a; short *b; int *c; 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc a = (char*) P; 8*f4a2713aSLionel Sambuc a = static_cast<char*>(P); 9*f4a2713aSLionel Sambuc a = reinterpret_cast<char*>(P); 10*f4a2713aSLionel Sambuc typedef char *CharPtr; 11*f4a2713aSLionel Sambuc a = CharPtr(P); 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}} 14*f4a2713aSLionel Sambuc b = reinterpret_cast<short*>(P); 15*f4a2713aSLionel Sambuc typedef short *ShortPtr; 16*f4a2713aSLionel Sambuc b = ShortPtr(P); // expected-warning {{cast from 'char *' to 'ShortPtr' (aka 'short *') increases required alignment from 1 to 2}} 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}} 19*f4a2713aSLionel Sambuc c = reinterpret_cast<int*>(P); 20*f4a2713aSLionel Sambuc typedef int *IntPtr; 21*f4a2713aSLionel Sambuc c = IntPtr(P); // expected-warning {{cast from 'char *' to 'IntPtr' (aka 'int *') increases required alignment from 1 to 4}} 22*f4a2713aSLionel Sambuc } 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc // Casts from void* are a special case. test1(void * P)25*f4a2713aSLionel Sambucvoid test1(void *P) { 26*f4a2713aSLionel Sambuc char *a; short *b; int *c; 27*f4a2713aSLionel Sambuc 28*f4a2713aSLionel Sambuc a = (char*) P; 29*f4a2713aSLionel Sambuc a = static_cast<char*>(P); 30*f4a2713aSLionel Sambuc a = reinterpret_cast<char*>(P); 31*f4a2713aSLionel Sambuc typedef char *CharPtr; 32*f4a2713aSLionel Sambuc a = CharPtr(P); 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc b = (short*) P; 35*f4a2713aSLionel Sambuc b = static_cast<short*>(P); 36*f4a2713aSLionel Sambuc b = reinterpret_cast<short*>(P); 37*f4a2713aSLionel Sambuc typedef short *ShortPtr; 38*f4a2713aSLionel Sambuc b = ShortPtr(P); 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc c = (int*) P; 41*f4a2713aSLionel Sambuc c = static_cast<int*>(P); 42*f4a2713aSLionel Sambuc c = reinterpret_cast<int*>(P); 43*f4a2713aSLionel Sambuc typedef int *IntPtr; 44*f4a2713aSLionel Sambuc c = IntPtr(P); 45*f4a2713aSLionel Sambuc } 46