According to the standard (or at least to cppreference) the std::get for std::tuple shall:
5-8) Extracts the element of the tuple t whose type is T. Fails to compile unless the tuple has exactly one element of that type.
So I interpret that sentence such that this code does not compile:
std::tuple<int, int> my_record;
std::get<int>(my_record) = 10;
Because two identical types exist and I try to access the tuple by type. However, both GCC an Clang correctly compile this code and produce the effect of modifying the first element.
Why? Am I misinterpreting the sentence on the reference? Is the reference wrong? Do GCC and Clang not respect the standard?
Looks like a GCC 11 bug, consider filing it. Here's the revelant part of the standard.
You see it in Clang because on gcc.godbolt.org it uses GCC's standard library by default. If you add -stdlib=libc++
to use it's own standard library, it refuses to compile it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With