[PATCH] D87561: [Sema] List conversion validate character array
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 13 13:11:14 PDT 2020
rsmith added inline comments.
================
Comment at: clang/lib/Sema/SemaOverload.cpp:4988
+
+ if (ToType->isArrayType() && ToType->isCharType() &&
+ isa<StringLiteral>(From->getInit(0))) {
----------------
`isCharType` is too narrow a check here. We also need to check for all the other types that can be initialized from a string literal (`wchar_t`, `char16_t`, ... -- including `unsigned short` in some cases). These details are handled by [`IsStringInit`](https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaInit.cpp#L136). Maybe it's worth exposing that as a `bool Sema::isStringInit` function or similar to use from here?
================
Comment at: clang/lib/Sema/SemaOverload.cpp:4989
+ if (ToType->isArrayType() && ToType->isCharType() &&
+ isa<StringLiteral>(From->getInit(0))) {
InitializedEntity Entity =
----------------
This is too narrow a check in two ways: we should allow parenthesized string literals here, and we should allow `ObjCEncodeExpr`.
================
Comment at: clang/lib/Sema/SemaOverload.cpp:4991-4992
InitializedEntity Entity =
- InitializedEntity::InitializeParameter(S.Context, ToType,
- /*Consumed=*/false);
+ InitializedEntity::InitializeParameter(S.Context, ToType,
+ /*Consumed=*/false);
if (S.CanPerformCopyInitialization(Entity, From)) {
----------------
Phabricator thinks you converted spaces to tabs here. Please can you check and convert back if necessary?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87561/new/
https://reviews.llvm.org/D87561
More information about the cfe-commits
mailing list