1 // RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s 2 // RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s -fexperimental-new-constant-interpreter 3 t1(void)4void t1(void) { 5 int array[1] = { 0 }; 6 char subscript = 0; 7 int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}} 8 } 9 t2(void)10void t2(void) { 11 int array[1] = { 0 }; 12 char subscript = 0; 13 int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}} 14 } 15 t3(void)16void t3(void) { 17 int *array = 0; 18 char subscript = 0; 19 int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}} 20 } 21 t4(void)22void t4(void) { 23 int *array = 0; 24 char subscript = 0; 25 int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}} 26 } 27 28 char returnsChar(void); t5(void)29void t5(void) { 30 int *array = 0; 31 int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}} 32 } 33 t6(void)34void t6(void) { 35 int array[1] = { 0 }; 36 signed char subscript = 0; 37 int val = array[subscript]; // no warning for explicit signed char 38 } 39 t7(void)40void t7(void) { 41 int array[1] = { 0 }; 42 unsigned char subscript = 0; 43 int val = array[subscript]; // no warning for unsigned char 44 } 45 46 typedef char CharTy; t8(void)47void t8(void) { 48 int array[1] = { 0 }; 49 CharTy subscript = 0; 50 int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}} 51 } 52 53 typedef signed char SignedCharTy; t9(void)54void t9(void) { 55 int array[1] = { 0 }; 56 SignedCharTy subscript = 0; 57 int val = array[subscript]; // no warning for explicit signed char 58 } 59 60 typedef unsigned char UnsignedCharTy; t10(void)61void t10(void) { 62 int array[1] = { 0 }; 63 UnsignedCharTy subscript = 0; 64 int val = array[subscript]; // no warning for unsigned char 65 } 66 t11(void)67void t11(void) { 68 int array[256] = { 0 }; 69 int val = array['a']; // no warning for char with known positive value 70 } 71 t12(void)72void t12(void) { 73 int array[256] = { 0 }; 74 char b = 'a'; 75 int val = array[b]; // expected-warning{{array subscript is of type 'char'}} 76 } 77 t13(void)78void t13(void) { 79 int array[256] = { 0 }; 80 const char b = 'a'; 81 int val = array[b]; // expected-warning{{array subscript is of type 'char'}} 82 } 83 t14(void)84void t14(void) { 85 int array[256] = { 0 }; // expected-note {{array 'array' declared here}} 86 const char b = -1; 87 // expected-warning@+2 {{array subscript is of type 'char'}} 88 // expected-warning@+1 {{array index -1 is before the beginning of the array}} 89 int val = array[b]; 90 } 91