91 lines · c
1// RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s2// RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s -fexperimental-new-constant-interpreter3 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 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 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 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 28char returnsChar(void);29void t5(void) {30 int *array = 0;31 int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}}32}33 34void t6(void) {35 int array[1] = { 0 };36 signed char subscript = 0;37 int val = array[subscript]; // no warning for explicit signed char38}39 40void t7(void) {41 int array[1] = { 0 };42 unsigned char subscript = 0;43 int val = array[subscript]; // no warning for unsigned char44}45 46typedef char CharTy;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 53typedef signed char SignedCharTy;54void t9(void) {55 int array[1] = { 0 };56 SignedCharTy subscript = 0;57 int val = array[subscript]; // no warning for explicit signed char58}59 60typedef unsigned char UnsignedCharTy;61void t10(void) {62 int array[1] = { 0 };63 UnsignedCharTy subscript = 0;64 int val = array[subscript]; // no warning for unsigned char65}66 67void t11(void) {68 int array[256] = { 0 };69 int val = array['a']; // no warning for char with known positive value70}71 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 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 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