Title
Missing noexcept specification in type_index
Status
c++14
Section
[type.index]
Submitter
Daniel Krügler

Created on 2012-03-18.00:00:00 last changed 123 months ago

Messages

Date: 2013-04-19.22:36:19

Proposed resolution:

This wording is relative to N3376.

  1. 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.
      };
    }
    
  1. 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()

Date: 2013-04-20.00:00:00

[ 2013-04-20 Bristol ]

Date: 2013-03-15.00:00:00

[ 2013-03-15 Issues Teleconference ]

Moved to Tentatively Ready.

Date: 2012-03-18.00:00:00

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 [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.

It seems both consistent and technically simply to require these functions to be noexcept.

History
Date User Action Args
2014-02-20 13:20:35adminsetstatus: wp -> c++14
2013-04-25 19:07:07adminsetstatus: voting -> wp
2013-04-19 22:36:19adminsetmessages: + msg6480
2013-04-19 22:36:19adminsetstatus: ready -> voting
2013-03-18 14:33:00adminsetmessages: + msg6405
2013-03-18 13:02:36adminsetstatus: new -> ready
2012-03-18 17:45:00adminsetmessages: + msg6066
2012-03-18 00:00:00admincreate