[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 12 05:03:02 PDT 2023
aaron.ballman added a subscriber: hubert.reinterpretcast.
aaron.ballman added inline comments.
================
Comment at: clang/test/SemaCXX/paren-list-agg-init.cpp:276-285
+namespace gh62863 {
+int (&&arr)[] = static_cast<int[]>(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arr1)[1] = static_cast<int[]>(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arrr2)[2] = static_cast<int[]>(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning at -1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
----------------
Fznamznon wrote:
> aaron.ballman wrote:
> > I'd like to see test coverage for:
> > ```
> > int (&&arr)[] = (int[])(42);
> > int (&&arr1)[1] = (int[])(42);
> > int (&&arrr2)[2] = (int[])(42);
> > int (&&arr3)[3] = (int[3])(42);
> > ```
> > where we're using a C-style cast, because: http://eel.is/c++draft/expr.cast#4
> Thank you for the review!
>
> Just to double check, so it says:
>
> > The conversions performed by ... *all named casts* can be performed using the cast notation of explicit type conversion.
>
> Does that mean the c-style cast should produce the same thing? And, https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1975r0.html doesn't say anything about c-style casts because it is assumed that it should be able to do anything that `static_cast` can do?
>
> gcc doesn't agree https://godbolt.org/z/Pfq8frdn9 . The funny thing is that the original bug report seems to be using some kind of gcc test.
> Does that mean the c-style cast should produce the same thing? And, https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1975r0.html doesn't say anything about c-style casts because it is assumed that it should be able to do anything that static_cast can do?
Correct
> gcc doesn't agree https://godbolt.org/z/Pfq8frdn9 . The funny thing is that the original bug report seems to be using some kind of gcc test.
MSVC and ICC both agree though, so I lean towards us being on the right path in allowing those casts. @hubert.reinterpretcast -- do you have thoughts?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152003/new/
https://reviews.llvm.org/D152003
More information about the cfe-commits
mailing list