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

            Bug ID: 103140
           Summary: __builtin_bit_cast To C array target type
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: patch
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wjwray at gmail dot com
  Target Milestone: ---

__builtin_bit_cast(To,from) can usefully be made to materialise a C array
as its target type To:

    __builtin_bit_cast( unsigned char[sizeof x], x );

Clang accepts this usage https://godbolt.org/z/n9dxeGecG
GCC rejects; error: '__builtin_bit_cast' destination type ... is an array type

Like __builtin_bit_cast itself, this change can apply to all -std modes.

This is a 'feature request' for tracking purposes; I'll attach a patch.
The patch was developed as part of an incoming implementation of P1997
but is independent, so makes sense to submit, review and merge ahead of it
(the feature is more useful in combination with P1997 array copy semantics,
 or otherwise provides basic array copy without need for a feature flag).

std::bit_cast<To>(from) is unchanged; it cannot return an array as specified,
as an otherwise regular library function, without extra compiler magic beyond
__builtin_bit_cast, unless / until P1997 is merged.

Reply via email to