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,
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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits