This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TC1 status.

222. Are throw clauses necessary if a throw is already implied by the effects clause?

Section: [structure.specifications] Status: TC1 Submitter: Judy Ward Opened: 2000-03-17 Last modified: 2016-01-28

Priority: Not Prioritized

View other active issues in [structure.specifications].

View all other issues in [structure.specifications].

View all issues with TC1 status.


Section describes the basic_string::compare function this way: - basic_string::compare [lib.string::compare]

int compare(size_type pos1, size_type n1,
                const basic_string<charT,traits,Allocator>&  str ,
                size_type  pos2 , size_type  n2 ) const;

-4- Returns: 

                 basic_string<charT,traits,Allocator>(str,pos2,n2)) .

and the constructor that's implicitly called by the above is defined to throw an out-of-range exception if pos > str.size(). See section [string.require] paragraph 4.

On the other hand, the compare function descriptions themselves don't have "Throws: " clauses and according to, paragraph 3, elements that do not apply to a function are omitted.

So it seems there is an inconsistency in the standard -- are the "Effects" clauses correct, or are the "Throws" clauses missing?

Proposed resolution:

In [structure.specifications] paragraph 3, the footnote 148 attached to the sentence "Descriptions of function semantics contain the following elements (as appropriate):", insert the word "further" so that the foot note reads:

To save space, items that do not apply to a function are omitted. For example, if a function does not specify any further preconditions, there will be no "Requires" paragraph.


The standard is somewhat inconsistent, but a failure to note a throw condition in a throws clause does not grant permission not to throw. The inconsistent wording is in a footnote, and thus non-normative. The proposed resolution from the LWG clarifies the footnote.