================ @@ -62,3 +62,28 @@ void t10(void) { UnsignedCharTy subscript = 0; int val = array[subscript]; // no warning for unsigned char } + +void t11(void) { + int array[256] = { 0 }; + int val = array['a']; // no warning for char with known positive value +} + +void t12(void) { + int array[256] = { 0 }; + char b = 'a'; + int val = array[b]; // expected-warning{{array subscript is of type 'char'}} +} + +void t13(void) { + int array[256] = { 0 }; + const char b = 'a'; + int val = array[b]; // expected-warning{{array subscript is of type 'char'}} +} + +void t14(void) { + int array[256] = { 0 }; // expected-note {{array 'array' declared here}} + const char b = -1; + // expected-warning@+2 {{array subscript is of type 'char'}} + // expected-warning@+1 {{array index -1 is before the beginning of the array}} + int val = array[b]; +} ---------------- wheatman wrote:
This behavior was not changed https://godbolt.org/z/4drrx6h9M since in `c` mode `b` is not considered a constant expression. These tests were added to since they were added in the `c++` file and I wanted to show the expected behavior in both languages. https://github.com/llvm/llvm-project/pull/69061 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits