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

--- Comment #6 from Daniel Fruzynski <bugzi...@poradnik-webmastera.com> ---
Not good. Fortunately I found workaround. This is probably the best what one
can get:

[code]
#include <stddef.h>
#include <stdint.h>

template<typename Type>
struct TypeHelper
{
    constexpr unsigned offset();

    operator Type&()
    {
        uint8_t*__restrict p = (uint8_t*__restrict)this - offset();
        Type*__restrict pt =  (Type*__restrict)p;
        return *pt;
    }
};

struct S
{
    struct Union
    {
        void*__restrict*__restrict ptr;
        TypeHelper<double*__restrict*__restrict> d;
    } u;
};

template<>
constexpr unsigned TypeHelper<double*__restrict*__restrict>::offset()
{
    return offsetof(S::Union, d) - offsetof(S::Union, ptr);
}

void test(S* __restrict s1, S* __restrict s2)
{
    for (int n = 0; n < 2; ++n)
    {
        s1->u.d[n][0] = s2->u.d[n][0];
        s1->u.d[n][1] = s2->u.d[n][1];
    }
}
[/code]

Reply via email to