[ORC-RT][LoongArch] Add initial support for loongarch64 in ELFNixPlatform (#123575)
[llvm-project.git] / clang / test / Sema / warn-char-subscripts.cpp
blob929fb372c5173fd9ce0bf9377808c80524768908
1 // RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s
3 void t1(void) {
4 int array[1] = { 0 };
5 char subscript = 0;
6 int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
9 void t2(void) {
10 int array[1] = { 0 };
11 char subscript = 0;
12 int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
15 void t3(void) {
16 int *array = 0;
17 char subscript = 0;
18 int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
21 void t4(void) {
22 int *array = 0;
23 char subscript = 0;
24 int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
27 char returnsChar(void);
28 void t5(void) {
29 int *array = 0;
30 int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}}
33 void t6(void) {
34 int array[1] = { 0 };
35 signed char subscript = 0;
36 int val = array[subscript]; // no warning for explicit signed char
39 void t7(void) {
40 int array[1] = { 0 };
41 unsigned char subscript = 0;
42 int val = array[subscript]; // no warning for unsigned char
45 typedef char CharTy;
46 void t8(void) {
47 int array[1] = { 0 };
48 CharTy subscript = 0;
49 int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
52 typedef signed char SignedCharTy;
53 void t9(void) {
54 int array[1] = { 0 };
55 SignedCharTy subscript = 0;
56 int val = array[subscript]; // no warning for explicit signed char
59 typedef unsigned char UnsignedCharTy;
60 void t10(void) {
61 int array[1] = { 0 };
62 UnsignedCharTy subscript = 0;
63 int val = array[subscript]; // no warning for unsigned char
66 void t11(void) {
67 int array[256] = { 0 };
68 int val = array['a']; // no warning for char with known positive value
71 void t12(void) {
72 int array[256] = { 0 };
73 char b = 'a';
74 int val = array[b]; // expected-warning{{array subscript is of type 'char'}}
77 void t13(void) {
78 int array[256] = { 0 };
79 const char b = 'a';
80 int val = array[b]; // no warning for char with known positive value
83 void t14(void) {
84 int array[256] = { 0 };
85 constexpr char b = 'a';
86 int val = array[b]; // no warning for char with known positive value
89 void t15(void) {
90 int array[256] = { 0 }; // expected-note {{array 'array' declared here}}
91 const char b = -1;
92 // expected-warning@+2 {{array subscript is of type 'char'}}
93 // expected-warning@+1 {{array index -1 is before the beginning of the array}}
94 int val = array[b];
97 void t16(void) {
98 int array[256] = { 0 }; // expected-note {{array 'array' declared here}}
99 constexpr char b = -1;
100 // expected-warning@+2 {{array subscript is of type 'char'}}
101 // expected-warning@+1 {{array index -1 is before the beginning of the array}}
102 int val = array[b];