[PATCH] D58896: Suppress -Wchar-subscripts if the index is a literal char
Edward Jones via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 7 07:51:06 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7adab7719e55: [Sema] Suppress -Wchar-subscripts if the index is a literal char (authored by edward-jones).
Herald added a subscriber: simoncook.
Changed prior to commit:
https://reviews.llvm.org/D58896?vs=189127&id=228249#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58896/new/
https://reviews.llvm.org/D58896
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/warn-char-subscripts.cpp
Index: clang/test/SemaCXX/warn-char-subscripts.cpp
===================================================================
--- clang/test/SemaCXX/warn-char-subscripts.cpp
+++ clang/test/SemaCXX/warn-char-subscripts.cpp
@@ -14,6 +14,19 @@
int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
}
+void t3() {
+ int array[50] = { 0 };
+ int val = array[' ']; // no warning, subscript is a literal
+}
+void t4() {
+ int array[50] = { 0 };
+ int val = '('[array]; // no warning, subscript is a literal
+}
+void t5() {
+ int array[50] = { 0 };
+ int val = array['\x11']; // no warning, subscript is a literal
+}
+
void test() {
t1<char>(); // expected-note {{in instantiation of function template specialization 't1<char>' requested here}}
t2<char>(); // expected-note {{in instantiation of function template specialization 't2<char>' requested here}}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4741,7 +4741,8 @@
if ((IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_S) ||
IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U))
- && !IndexExpr->isTypeDependent())
+ && !IndexExpr->isTypeDependent()
+ && !isa<CharacterLiteral>(IndexExpr))
Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange();
// C99 6.5.2.1p1: "shall have type "pointer to *object* type". Similarly,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58896.228249.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191107/687ec666/attachment.bin>
More information about the cfe-commits
mailing list