[PATCH] D87561: [Sema] List conversion validate character array

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 16 17:33:06 PDT 2020


rsmith added inline comments.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:4989
+    if (ToType->isArrayType() && ToType->isCharType() &&
+        isa<StringLiteral>(From->getInit(0))) {
       InitializedEntity Entity =
----------------
Mordante wrote:
> rsmith wrote:
> > This is too narrow a check in two ways: we should allow parenthesized string literals here, and we should allow `ObjCEncodeExpr`.
> Actually it seems the code isn't behaving properly at all. It seems the conversion is done by
> https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaOverload.cpp#L5174
> resulting in an array-to-pointer conversion instead of an identity conversion.
> 
> It can solve it by manually removing the decay like:
> ```
>     if (const auto *DT = dyn_cast<DecayedType>(ToType))
>       if (const auto *AT = S.Context.getAsArrayType(DT->getOriginalType()))
>         if (S.IsStringInit(From->getInit(0), AT) {
>            ...
> ```
> This code works and results in an identity conversion. But it feels a bit odd to manually peel away the array-to-pointer decay. Is this the best solution or do you have a better suggestions?
>   
> 
I think this is a bug in your testcases. I'll comment below.


================
Comment at: clang/test/CXX/drs/dr14xx.cpp:411-414
+  void f(const char[4]);
+  void f(const wchar_t[4]);
+  void f(const char16_t[4]);
+  void f(const char32_t[4]);
----------------
These should presumably be references to arrays, rather than arrays, or the parameter type is as if you wrote (for example) `void f(const char *)`, which shouldn't get the special treatment here.

[over.ics.list]p4 mentions this in its footnote:

"Otherwise, if the parameter type is a character array [Footnote: Since there are no parameters of array type, this will only occur as the referenced type of a reference parameter.] and the initializer list has a single element that is an appropriately-typed string-literal (9.4.3), the implicit conversion sequence is the identity conversion."


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