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

--- Comment #3 from pskocik at gmail dot com ---
jos...@codesourcery.com, that's interesting, but it seems like an unnecessary,
weird special case, considering that gcc already has a qualifier-dropping
mechanism that doesn't necessitate special-casing __typeof for
_Atomic-qualified types.

Casting an expression to its own type (which on gcc works for aggregates too)
doe it.

Compilable example:

#if __clang__
        #define DROP_Q(X) ((void)0,X) //clang rejects the casts for aggregate
types
#else
        #define DROP_Q(X) (__extension__({ (__typeof(X))(X) ; }))
//__extension__ so aggregates are accepted
                //even under -pedantic
#endif
int main(void)
{
        #define TEST_RVAL_CONV(Tp) \
        do{ \
        _Atomic const volatile  Tp abar; \
        const volatile  Tp bar; \
        __typeof(DROP_Q(bar)) noqualif_bar; \
        __typeof(DROP_Q(abar)) noqualif_abar; \
        _Generic(&noqualif_bar, Tp*: (void)0); \
        _Generic(&noqualif_abar, Tp*: (void)0); \
        }while(0)

        TEST_RVAL_CONV(int);
        TEST_RVAL_CONV(__typeof(int*));
        typedef struct s_tp { int x; } s_tp;
        TEST_RVAL_CONV(s_tp);
}

https://gcc.godbolt.org/z/UtMyxM

I think all lvalue-ness-dropping expressions (e.g., the comma operator or ?: )
ought to drop top-level qualifs too (and they do on clang), and such a
qualif-dropping operation wouldn't then be dependent on the gcc extension of
allowing casts to non-scalar types, but unfortunately, gcc does not drop
top-level qualifs in rvalue-conversions, which means the clang implementation
of the qualifier-dropping macro doesn't work on gcc.

Reply via email to