Home | History | Annotate | Download | only in Sema
      1 // RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s
      2 
      3 void t1() {
      4   int array[1] = { 0 };
      5   char subscript = 0;
      6   int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
      7 }
      8 
      9 void t2() {
     10   int array[1] = { 0 };
     11   char subscript = 0;
     12   int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
     13 }
     14 
     15 void t3() {
     16   int *array = 0;
     17   char subscript = 0;
     18   int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
     19 }
     20 
     21 void t4() {
     22   int *array = 0;
     23   char subscript = 0;
     24   int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
     25 }
     26 
     27 char returnsChar();
     28 void t5() {
     29   int *array = 0;
     30   int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}}
     31 }
     32 
     33 void t6() {
     34   int array[1] = { 0 };
     35   signed char subscript = 0;
     36   int val = array[subscript]; // no warning for explicit signed char
     37 }
     38 
     39 void t7() {
     40   int array[1] = { 0 };
     41   unsigned char subscript = 0;
     42   int val = array[subscript]; // no warning for unsigned char
     43 }
     44 
     45 typedef char CharTy;
     46 void t8() {
     47   int array[1] = { 0 };
     48   CharTy subscript = 0;
     49   int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
     50 }
     51 
     52 typedef signed char SignedCharTy;
     53 void t9() {
     54   int array[1] = { 0 };
     55   SignedCharTy subscript = 0;
     56   int val = array[subscript]; // no warning for explicit signed char
     57 }
     58 
     59 typedef unsigned char UnsignedCharTy;
     60 void t10() {
     61   int array[1] = { 0 };
     62   UnsignedCharTy subscript = 0;
     63   int val = array[subscript]; // no warning for unsigned char
     64 }
     65