]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Improve diagnostics for std::get with invalid tuple index
authorJonathan Wakely <jwakely@redhat.com>
Fri, 16 Jul 2021 19:59:43 +0000 (20:59 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 16 Jul 2021 21:24:34 +0000 (22:24 +0100)
commit3dbc7b809a62167b36f217ab5f43207be19e5908
tree03e1db21d551a906f19e2f1bafab5af6b965c635
parenta8b3861496bffae8b813ea196c1c5b27f79fbe69
libstdc++: Improve diagnostics for std::get with invalid tuple index

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.
libstdc++-v3/include/std/tuple
libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc