Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s
      2 
      3 // Simple casts.
      4 void 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}}
     14   b = reinterpret_cast<short*>(P);
     15   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}}
     19   c = reinterpret_cast<int*>(P);
     20   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.
     25 void 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 }
     46