================ @@ -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]; +} ---------------- AaronBallman wrote:
These two both surprise me in a C file; `b` is not an integer constant expression in either case, so I would have expected no diagnostic here. The diagnostic is defensible, just a surprise. 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