forked from OSchip/llvm-project
-Wchar-subscripts should not warn for unsigned char subscripts. Fixes PR4978.
llvm-svn: 81776
This commit is contained in:
parent
5be00aae4f
commit
80cf843fe9
|
@ -1809,7 +1809,9 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc,
|
|||
return ExprError(Diag(LLoc, diag::err_typecheck_subscript_not_integer)
|
||||
<< IndexExpr->getSourceRange());
|
||||
|
||||
if (IndexExpr->getType()->isCharType() && !IndexExpr->isTypeDependent())
|
||||
QualType IndexTy = Context.getCanonicalType(IndexExpr->getType());
|
||||
if ((IndexTy == Context.CharTy || IndexTy == Context.SignedCharTy)
|
||||
&& !IndexExpr->isTypeDependent())
|
||||
Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange();
|
||||
|
||||
// C99 6.5.2.1p1: "shall have type "pointer to *object* type". Similarly,
|
||||
|
|
|
@ -29,3 +29,36 @@ void t5() {
|
|||
int *array = 0;
|
||||
int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}}
|
||||
}
|
||||
|
||||
void t6() {
|
||||
int array[1] = { 0 };
|
||||
signed char subscript = 0;
|
||||
int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
|
||||
}
|
||||
|
||||
void t7() {
|
||||
int array[1] = { 0 };
|
||||
unsigned char subscript = 0;
|
||||
int val = array[subscript]; // no warning for unsigned char
|
||||
}
|
||||
|
||||
typedef char CharTy;
|
||||
void t8() {
|
||||
int array[1] = { 0 };
|
||||
CharTy subscript = 0;
|
||||
int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
|
||||
}
|
||||
|
||||
typedef signed char SignedCharTy;
|
||||
void t9() {
|
||||
int array[1] = { 0 };
|
||||
SignedCharTy subscript = 0;
|
||||
int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
|
||||
}
|
||||
|
||||
typedef unsigned char UnsignedCharTy;
|
||||
void t10() {
|
||||
int array[1] = { 0 };
|
||||
UnsignedCharTy subscript = 0;
|
||||
int val = array[subscript]; // no warning for unsigned char
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue