noexcept
specification in type_index
Section: 17.7.7 [type.index] Status: C++14 Submitter: Daniel Krügler Opened: 2012-03-18 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [type.index].
View all issues with C++14 status.
Discussion:
The class type type_index
is a thin wrapper of type_info
to
adapt it as a valid associative container element. Similar to type_info
,
all member functions have an effective noexcept(true)
specification, with the
exception of hash_code()
and name()
. The actual effects of these
functions is a direct call to type_info
's hash_code()
and name
function, but according to 17.7 [support.rtti] these are both noexcept
functions, so there is no reason for not declaring them as noexcept
, too. In fact,
one of the suggested changes of the original proposing paper
N2530
specifically was to ensure that type_info
would get a hash_code()
function that guarantees not to throw exceptions (during that time the hash
requirements did not allow to exit with an exception). From this we can conclude that
type_index::hash_code()
was intended to be nothrow.
noexcept
.
[2013-03-15 Issues Teleconference]
Moved to Tentatively Ready.
[2013-04-20 Bristol]
Proposed resolution:
This wording is relative to N3376.
Modify the class type_index
synopsis, [type.index.overview] as indicated:
namespace std { class type_index { public: type_index(const type_info& rhs) noexcept; bool operator==(const type_index& rhs) const noexcept; bool operator!=(const type_index& rhs) const noexcept; bool operator< (const type_index& rhs) const noexcept; bool operator<= (const type_index& rhs) const noexcept; bool operator> (const type_index& rhs) const noexcept; bool operator>= (const type_index& rhs) const noexcept; size_t hash_code() const noexcept; const char* name() const noexcept; private: const type_info* target; // exposition only // Note that the use of a pointer here, rather than a reference, // means that the default copy/move constructor and assignment // operators will be provided and work as expected. }; }
Modify the prototype definitions in [type.index.members] as indicated:
size_t hash_code() const noexcept;-8- Returns:
target->hash_code()
const char* name() const noexcept;-9- Returns:
target->name()