[committed] libstdc++: Improve diagnostics for std::get with invalid tuple index

Jonathan Wakely jwakely@redhat.com
Fri Jul 16 22:08:30 GMT 2021


The recent fix for std::get<T> uses a deleted overload to give better
diagnostics for out-of-range indices. This does something similar for
std::get<I>.

Tested powerpc64le-linux. Committed to trunk.


This adds a deleted overload of std::get<I>(const tuple<Types...>&).
Invalid calls with an out of range index will match the deleted overload
and give a single, clear error about calling a deleted function, instead
of overload resolution errors for every std::get overload in the
library.

This changes the current output of 15+ errors (plus notes and associated
header context) into just two errors (plus context):

error: static assertion failed: tuple index must be in range
error: use of deleted function 'constexpr std::__enable_if_t<(__i >= sizeof... (_Types))> std::get(const std::tuple<_Types ...>&) [with long unsigned int __i = 1; _Elements = {int}; std::__enable_if_t<(__i >= sizeof... (_Types))> = void]'

This seems like a nice improvement, although PR c++/66968 means that
"_Types" is printed in the signature rather than "_Elements".

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

         * include/std/tuple (get<I>): Add deleted overload for bad
         index.
         * testsuite/20_util/tuple/element_access/get_neg.cc: Adjust
         expected errors.




-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 5281 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210716/1a8bf3f5/attachment.bin>


More information about the Libstdc++ mailing list