Sam Weinig | 76e2b71 | 2009-09-14 01:58:58 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -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 | } |
Sam Weinig | b0a2290 | 2009-09-14 18:17:16 +0000 | [diff] [blame^] | 32 | |
| 33 | void t6() { |
| 34 | int array[1] = { 0 }; |
| 35 | signed char subscript = 0; |
| 36 | int val = array[subscript]; // expected-warning{{array subscript is of type '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]; // expected-warning{{array subscript is of type '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 | } |