[cfe-commits] r81780 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/warn-char-subscripts.c

Sam Weinig sam.weinig at gmail.com
Mon Sep 14 13:14:58 PDT 2009


Author: weinig
Date: Mon Sep 14 15:14:57 2009
New Revision: 81780

URL: http://llvm.org/viewvc/llvm-project?rev=81780&view=rev
Log:
-Wchar-subscripts should not warn for explicit signed char subscripts either. Another fix for 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=81780&r1=81779&r2=81780&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 14 15:14:57 2009
@@ -1809,9 +1809,9 @@
     return ExprError(Diag(LLoc, diag::err_typecheck_subscript_not_integer)
                      << IndexExpr->getSourceRange());
 
-  QualType IndexTy = Context.getCanonicalType(IndexExpr->getType());
-  if ((IndexTy == Context.CharTy || IndexTy == Context.SignedCharTy)
-      && !IndexExpr->isTypeDependent())
+  if ((IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_S) || 
+       IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U))
+         && !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=81780&r1=81779&r2=81780&view=diff

==============================================================================
--- cfe/trunk/test/Sema/warn-char-subscripts.c (original)
+++ cfe/trunk/test/Sema/warn-char-subscripts.c Mon Sep 14 15:14:57 2009
@@ -33,7 +33,7 @@
 void t6() {
   int array[1] = { 0 };
   signed char subscript = 0;
-  int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+  int val = array[subscript]; // no warning for explicit signed char
 }
 
 void t7() {
@@ -53,7 +53,7 @@
 void t9() {
   int array[1] = { 0 };
   SignedCharTy subscript = 0;
-  int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+  int val = array[subscript]; // no warning for explicit signed char
 }
 
 typedef unsigned char UnsignedCharTy;





More information about the cfe-commits mailing list