[cfe-commits] r81776 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/warn-char-subscripts.c
Sam Weinig
sam.weinig at gmail.com
Mon Sep 14 11:17:16 PDT 2009
Author: weinig
Date: Mon Sep 14 13:17:16 2009
New Revision: 81776
URL: http://llvm.org/viewvc/llvm-project?rev=81776&view=rev
Log:
-Wchar-subscripts should not warn for unsigned char subscripts. Fixes PR4978.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/warn-char-subscripts.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=81776&r1=81775&r2=81776&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 14 13:17:16 2009
@@ -1809,7 +1809,9 @@
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,
Modified: cfe/trunk/test/Sema/warn-char-subscripts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-char-subscripts.c?rev=81776&r1=81775&r2=81776&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-char-subscripts.c (original)
+++ cfe/trunk/test/Sema/warn-char-subscripts.c Mon Sep 14 13:17:16 2009
@@ -29,3 +29,36 @@
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
+}
More information about the cfe-commits
mailing list