Unfortunately, I have no idea how to test this, the one and only reproducer I have so far is:
#include <array> constexpr std::array<int, 10> IntArray = {};
which results in a InitListExpr containing a ImplicitValueInitExpr with an array type.
Differential D135013
[clang][Interp] Array initialization via ImplicitValueInitExpr tbaeder on Oct 1 2022, 12:34 AM. Authored by
Details Unfortunately, I have no idea how to test this, the one and only reproducer I have so far is: #include <array> constexpr std::array<int, 10> IntArray = {}; which results in a InitListExpr containing a ImplicitValueInitExpr with an array type.
Diff Detail
Event TimelineComment Actions The following also generates an ImplicitValueInitExpr: template <typename T, unsigned N> struct B { T a[N]; }; int main() { constexpr B<int,10> arr = {}; constexpr int x = arr.a[0]; } Comment Actions Thanks for the reproducer!
Comment Actions I found a way to get ImplictValueInitExpr for a record: https://godbolt.org/z/Eqf9Gz1G4 I am not sure if we can achieve the same in C++ b/c value init of a class break down to default init or zero init. Comment Actions Does clang generate a default constructor in this case anyway, which the interpreter could use in this case? Or is it support to just memset(0) the entire struct instance? Comment Actions @aaron.ballman Do you maybe have a different reproducer or know more about the expected behavior of a ImplicitValueInitExpr for array and record types? Comment Actions So here's another reproducer with a record type: https://godbolt.org/z/EhT4oqT3s and here's one with an array type: https://godbolt.org/z/Pbncnq418 My understanding of ImplicitValueInitExpr is that it's used to represent some of the "holes" in the middle of an array/record that need to implicit get some values. Comment Actions They are inside a struct or array, but not of array or struct type, if I understand correctly. But I see what you're getting at, I guess this should basically go through visitZeroInitializer() (which is currently unused), which should be extended to handle structs and arrays. Comment Actions Ah, yes! That's true, they are inside the struct or array. I'm not certain you can have one *of* struct type in C++ because it's either going to be zeroed or left uninitialized (due to constructors). Comment Actions Thinking about it some more, doesn't make much sense to add all that right now when we don't have a reproducer to test it anyway. I think the patch as it is makes sense and it it's not enough in the future, there's a proper assert in place. Comment Actions Aside from a naming quirk, LGTM
|
Please spell out the type.