C++ Logo

std-discussion

Advanced search

Can a std::meta::info be bit_casted?

From: Keenan Horrigan <friedkeenan_at_[hidden]>
Date: Fri, 06 Feb 2026 20:14:51 +0000
I was playing around with the C++26 reflection stuff a bit, and realized that since std::meta::info is a scalar type, and all scalar types are trivially-copyable, then std::meta::info should be trivially-copyable and therefore bit_castable.

Of course I have no real idea what that would actually result in, and indeed currently GCC trunk raises an error and says that it is unimplemented:

/cefs/55/552701a8be9eb5ce4ab990a8_gcc-trunk-20260206/include/c++/16.0.1/bit: In function 'int main()':
in 'constexpr' expansion of 'std::bit_cast<array<char, 8>, std::meta::info>(info)'
<source>:7:63:
    7 | constexpr auto casted = std::bit_cast<std::array<char, 8>>(info);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/cefs/55/552701a8be9eb5ce4ab990a8_gcc-trunk-20260206/include/c++/16.0.1/bit:96:33: sorry, unimplemented: '__builtin_bit_cast' cannot be constant evaluated because the argument cannot be encoded
   96 | return __builtin_bit_cast(_To, __from);
      | ^~~

Theoretically as well, it could only be done during constant evaluation due to std::meta::info being a consteval-only type.

I suppose it might come down to what is the "value representation" of a std::meta::info, which I believe is implementation-defined. But then even at the extreme, if it were somehow that there are zero bits in the value representation of a std::meta::info, then I believe it should just yield a sequence of indeterminate bytes in that case, no? Though looking at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99637 it seems there may be some question as to whether that should still result in an error, anyways.

But regardless, is this a gap in the standard? It doesn't appear very meaningful either way, but I'm curious.

Thanks

Received on 2026-02-06 20:14:56