[Bug c++/104920] Unreliable results with memset-elt-size

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Mar 14 18:32:29 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104920

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
E.g. in the above #c0 testcase, you can see it in the -fdump-tree-gimple dump:
        memset (&arr, 0, 10);
        _1 = std::array<int, 10>::data (&arr2);
        memset (_1, 0, 10);
For the arr case, the FE can see the array and the size, while for the other
case
it can only see the size to be constant (even that goes beyond what the
language guarantees, as the size is passed outside of manifestly constant
evaluated context, so nothing guarantees it is constant evaluated).
But, if you e.g. add
    constexpr auto p = arr2.data();
to your #c0 testcase, you'll see it is not a constant expression:
error: ‘(int*)(& arr2.std::array<int, 10>::_M_elems)’ is not a constant
expression


More information about the Gcc-bugs mailing list