Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s |
Sam Weinig | 76e2b71 | 2009-09-14 01:58:58 +0000 | [diff] [blame] | 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; |
Sam Weinig | 0f9a5b5 | 2009-09-14 20:14:57 +0000 | [diff] [blame] | 36 | int val = array[subscript]; // no warning for explicit signed char |
Sam Weinig | b0a2290 | 2009-09-14 18:17:16 +0000 | [diff] [blame] | 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; |
Sam Weinig | 0f9a5b5 | 2009-09-14 20:14:57 +0000 | [diff] [blame] | 56 | int val = array[subscript]; // no warning for explicit signed char |
Sam Weinig | b0a2290 | 2009-09-14 18:17:16 +0000 | [diff] [blame] | 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 | } |