Doc. no. N3893
Date: 2014-01-20
Project: Programming Language C++
Reply to: Alisdair Meredith <lwgchair@gmail.com>

C++ Standard Library Active Issues List (Revision R86)

Revised 2014-01-20 at 23:01:51 UTC

Reference ISO/IEC IS 14882:2011(E)

Also see:

The purpose of this document is to record the status of issues which have come before the Library Working Group (LWG) of the INCITS PL22.16 and ISO WG21 C++ Standards Committee. Issues represent potential defects in the ISO/IEC IS 14882:2011(E) document.

This document contains only library issues which are actively being considered by the Library Working Group, i.e., issues which have a status of New, Open, Ready, or Review. See Library Defect Reports List for issues considered defects and Library Closed Issues List for issues considered closed.

The issues in these lists are not necessarily formal ISO Defect Reports (DR's). While some issues will eventually be elevated to official Defect Report status, other issues will be disposed of in other ways. See Issue Status.

Prior to Revision 14, library issues lists existed in two slightly different versions; a Committee Version and a Public Version. Beginning with Revision 14 the two versions were combined into a single version.

This document includes [bracketed italicized notes] as a reminder to the LWG of current progress on issues. Such notes are strictly unofficial and should be read with caution as they may be incomplete or incorrect. Be aware that LWG support for a particular resolution can quickly change if new viewpoints or killer examples are presented in subsequent discussions.

For the most current official version of this document see http://www.open-std.org/jtc1/sc22/wg21/. Requests for further information about this document should include the document number above, reference ISO/IEC 14882:2011(E), and be submitted to Information Technology Industry Council (ITI), 1250 Eye Street NW, Washington, DC 20005.

Public information as to how to obtain a copy of the C++ Standard, join the standards committee, submit an issue, or comment on an issue can be found in the comp.std.c++ FAQ.

How to submit an issue

  1. Mail your issue to the author of this list.
  2. Specify a short descriptive title. If you fail to do so, the subject line of your mail will be used as the issue title.
  3. If the "From" on your email is not the name you wish to appear as issue submitter, then specify issue submitter.
  4. Provide a brief discussion of the problem you wish to correct. Refer to the latest working draft or standard using [section.tag] and paragraph numbers where appropriate.
  5. Provide proposed wording. This should indicate exactly how you want the standard to be changed. General solution statements belong in the discussion area. This area contains very clear and specific directions on how to modify the current draft. If you are not sure how to word a solution, you may omit this part. But your chances of a successful issue greatly increase if you attempt wording.
  6. It is not necessary for you to use html markup. However, if you want to, you can <ins>insert text like this</ins> and <del>delete text like this</del>. The only strict requirement is to communicate clearly to the list maintainer exactly how you want your issue to look.
  7. It is not necessary for you to specify other html font/formatting mark-up, but if you do the list maintainer will attempt to respect your formatting wishes (as described by html markup, or other common idioms).
  8. It is not necessary for you to specify open date or last modified date (the date of your mail will be used).
  9. It is not necessary for you to cross reference other issues, but you can if you like. You do not need to form the hyperlinks when you do, the list maintainer will take care of that.
  10. One issue per email is best.
  11. Between the time you submit the issue, and the next mailing deadline (date at the top of the Revision History), you own this issue. You control the content, the stuff that is right, the stuff that is wrong, the format, the misspellings, etc. You can even make the issue disappear if you want. Just let the list maintainer know how you want it to look, and he will try his best to accommodate you. After the issue appears in an official mailing, you no longer enjoy exclusive ownership of it.

Revision History

Issue Status

Issues reported to the LWG transition through a variety of statuses, indicating their progress towards a resolution. Typically, most issues will flow through the following stages.

New - The issue has not yet been reviewed by the LWG. Any Proposed Resolution is purely a suggestion from the issue submitter, and should not be construed as the view of LWG.

Open - The LWG has discussed the issue but is not yet ready to move the issue forward. There are several possible reasons for open status:

A Proposed Resolution for an open issue is still not be construed as the view of LWG. Comments on the current state of discussions are often given at the end of open issues in an italic font. Such comments are for information only and should not be given undue importance.

Review - Exact wording of a Proposed Resolution is now available for review on an issue for which the LWG previously reached informal consensus.

Ready - The LWG has reached consensus that the issue is a defect in the Standard, the Proposed Resolution is correct, and the issue is ready to forward to the full committee for further action as a Defect Report (DR).

Typically, an issue must have a proposed resolution in the currently published issues list, whose wording does not change during LWG review, to move to the Ready status.

Voting - This status should not be seen in a published issues list, but is a marker for use during meetings to indicate an issues was Ready in the pre-meeting mailing, the Proposed Resolution is correct, and the issue will be offered to the working group at the end of the current meeting to apply to the current working paper (WP) or to close in some other appropriate manner. This easily distinguishes such issues from those moving to Ready status during the meeting itself, that should not be forwarded until the next meeting. If the issue does not move forward, it should fall back to one of the other open states before the next list is published.

Immediate - This status should not be seen in a published issues list, but is a marker for use during meetings to indicate an issues was not Ready in the pre-meeting mailing, but the Proposed Resolution is correct, and the issue will be offered to the working group at the end of the current meeting to apply to the current working paper (WP) or to close in some other appropriate manner. This status is used only rarely, typically for fixes that are both small and obvious, and usually within a meeting of the expected publication of a revised standard. If the issue does not move forward, it should fall back to one of the other open states before the next list is published.

In addition, there are a few ways to categorise and issue that remains open to a resolution within the library, but is not actively being worked on.

Deferred - The LWG has discussed the issue, is not yet ready to move the issue forward, but neither does it deem the issue significant enough to delay publishing a standard or Technical Report. A typical deferred issue would be seeking to clarify wording that might be technically correct, but easily mis-read.

A Proposed Resolution for a deferred issue is still not be construed as the view of LWG. Comments on the current state of discussions are often given at the end of open issues in an italic font. Such comments are for information only and should not be given undue importance.

Core - The LWG has discussed the issue, and feels that some key part of resolving the issue is better handled by a cleanup of the language in the Core part of the standard. The issue is passed to the Core Working Group, which should ideally open a corresponding issue that can be linked from the library issue. Such issues will be revisitted after Core have made (or declined to make) any changes.

EWG - The LWG has discussed the issue, and wonder that some key part of resolving the issue is better handled by some (hopefully small) extension to the language. The issue is passed to the Evolution Working Group, which should ideally open a corresponding issue that can be linked from the library issue. Such issues will be revisitted after Evoltion have made (or declined to make) any recommendations. Positive recommendations from EWG will often mean the issue transition to Core status while we wait for some proposed new feature to land in the working paper.

Ultimately, all issues should reach closure with one of the following statuses.

DR - (Defect Report) - The full WG21/PL22.16 committee has voted to forward the issue to the Project Editor to be processed as a Potential Defect Report. The Project Editor reviews the issue, and then forwards it to the WG21 Convenor, who returns it to the full committee for final disposition. This issues list accords the status of DR to all these Defect Reports regardless of where they are in that process.

WP - (Working Paper) - The proposed resolution has not been accepted as a Technical Corrigendum, but the full WG21/PL22.16 committee has voted to apply the Defect Report's Proposed Resolution to the working paper.

C++11 - (C++ Standard, as revised for 2011) - The full WG21/PL22.16 committee has voted to accept the Defect Report's Proposed Resolution into the published 2011 revision to the C++ standard, ISO/IEC IS 14882:2011(E).

CD1 - (Committee Draft 2008) - The full WG21/PL22.16 committee has voted to accept the Defect Report's Proposed Resolution into the Fall 2008 Committee Draft.

TC1 - (Technical Corrigenda 1) - The full WG21/PL22.16 committee has voted to accept the Defect Report's Proposed Resolution as a Technical Corrigenda. Action on this issue is thus complete and no further action is possible under ISO rules.

TRDec - (Decimal TR defect) - The LWG has voted to accept the Defect Report's Proposed Resolution into the Decimal TR. Action on this issue is thus complete and no further action is expected.

Resolved - The LWG has reached consensus that the issue is a defect in the Standard, but the resolution adopted to resolve the issue came via some other mechanism than this issue in the list - typically by applying a formal paper, occasionally as a side effect of consolidating several interacting issue resolutions into a single issue.

Dup - The LWG has reached consensus that the issue is a duplicate of another issue, and will not be further dealt with. A Rationale identifies the duplicated issue's issue number.

NAD - The LWG has reached consensus that the issue is not a defect in the Standard.

NAD Editorial - The LWG has reached consensus that the issue can either be handled editorially, or is handled by a paper (usually linked to in the rationale).

NAD Future - In addition to the regular status, the LWG believes that this issue should be revisited at the next revision of the standard.

NAD Concepts - This status reflects an evolution of the language during the development of C++11, where a new feature entered the language, called concepts, that fundamentally changed the way templates would be specified and written. While this language feature was removed towards the end of the C++11 project, there is a clear intent to revisit this part of the language design. During that development, a number of issues were opened against the updated library related to use of that feature, or requesting fixes that would require exliciit use of the concepts feature. All such issues have been closed with this status, and may be revisitted should this or a similar language feature return for a future standard.

Tentatively - This is a status qualifier. The issue has been reviewed online, or at an unofficial meeting, but not in an official meeting, and some support has been formed for the qualified status. Tentatively qualified issues may be moved to the unqualified status and forwarded to full committee (if Ready) within the same meeting. Unlike Ready issues, Tentatively Ready issues will be reviewed in subcommittee prior to forwarding to full committee. When a status is qualified with Tentatively, the issue is still considered active.

Pending - This is a status qualifier. When prepended to a status this indicates the issue has been processed by the committee, and a decision has been made to move the issue to the associated unqualified status. However for logistical reasons the indicated outcome of the issue has not yet appeared in the latest working paper.

Issues are always given the status of New when they first appear on the issues list. They may progress to Open or Review while the LWG is actively working on them. When the LWG has reached consensus on the disposition of an issue, the status will then change to Dup, NAD, or Ready as appropriate. Once the full PL22.16 committee votes to forward Ready issues to the Project Editor, they are given the status of Defect Report ( DR). These in turn may become the basis for Technical Corrigenda (TC1), or are closed without action other than a Record of Response (Resolved ). The intent of this LWG process is that only issues which are truly defects in the Standard move to the formal ISO DR status.

Active Issues


1169. num_get not fully compatible with strto*

Section: 22.4.2.1.2 [facet.num.get.virtuals] Status: Open Submitter: Cosmin Truta Opened: 2009-07-04 Last modified: 2013-10-15

View all other issues in [facet.num.get.virtuals].

View all issues with Open status.

Discussion:

As specified in the latest draft, N2914, num_get is still not fully compatible with the following C functions: strtoul, strtoull, strtof and strtod.

In C, when conversion of a string to an unsigned integer type falls outside the representable range, strtoul and strtoull return ULONG_MAX and ULLONG_MAX, respectively, regardless whether the input field represents a positive or a negative value. On the other hand, the result of num_get conversion of negative values to unsigned integer types is zero. This raises a compatibility issue.

Moreover, in C, when conversion of a string to a floating-point type falls outside the representable range, strtof, strtod and strtold return ±HUGE_VALF, ±HUGE_VAL and ±HUGE_VALL, respectively. On the other hand, the result of num_get conversion of such out-of-range floating-point values results in the most positive/negative representable value. Although many C library implementations do implement HUGE_VAL (etc.) as the highest representable (which is, usually, the infinity), this isn't required by the C standard. The C library specification makes no statement regarding the value of HUGE_VAL and friends, which potentially raises the same compatibility issue as in the above case of unsigned integers. In addition, neither C nor C++ define symbolic constants for the maximum representable floating-point values (they only do so only for the maximum representable finite floating-point values), which raises a usability issue (it would be hard for the programmer to check the result of num_get against overflow).

As such, we propose to adjust the specification of num_get to closely follow the behavior of all of its underlying C functions.

[ 2010 Rapperswil: ]

Some concern that this is changing the specification for an existing C++03 function, but it was pointed out that this was underspecified as resolved by issue 23. This is clean-up for that issue in turn. Some concern that we are trying to solve the same problem in both clause 22 and 27.

Bill: There's a change here as to whether val is stored to in an error case.

Pablo: Don't think this changes whether val is stored to or not, but changes the value that is stored.

Bill: Remembers having skirmishes with customers and testers as to whether val is stored to, and the resolution was not to store in error cases.

Howard: Believes since C++03 we made a change to always store in overflow.

Everyone took some time to review the issue.

Pablo: C++98 definitely did not store any value during an error condition.

Dietmar: Depends on the question of what is considered an error, and whether overflow is an error or not, which was the crux of LWG 23.

Pablo: Yes, but given the "zero, if the conversion function fails to convert the entire field", we are requiring every error condition to store.

Bill: When did this happen?

Alisdair: One of the last two or three meetings.

Dietmar: To store a value in case of failure is a very bad idea.

Move to Open, needs more study.

[2011-03-24 Madrid meeting]

Move to deferred

[ 2011 Bloomington ]

The proposed wording looks good, no-one sure why this was held back before. Move to Review.

[2012,Kona]

Move to Open.

THe issues is what to do with -1. Should it match 'C' or do the "sane" thing. A fix here changes behavior, but is probably what we want.

Pablo to provide wording, with help from Howard.

Proposed resolution:

Change 22.4.2.1.2 [facet.num.get.virtuals] as follows:

Stage 3: The sequence of chars accumulated in stage 2 (the field) is converted to a numeric value by the rules of one of the functions declared in the header <cstdlib>:

The numeric value to be stored can be one of:

The resultant numeric value is stored in val. If the conversion function fails to convert the entire field, or if the field represents a value outside the range of representable values, ios_base::failbit is assigned to err.


1175. unordered complexity

Section: 23.2.5 [unord.req] Status: Open Submitter: Pablo Halpern Opened: 2009-07-17 Last modified: 2012-11-14

View other active issues in [unord.req].

View all other issues in [unord.req].

View all issues with Open status.

Discussion:

When I look at the unordered_* constructors, I think the complexity is poorly described and does not follow the style of the rest of the standard.

The complexity for the default constructor is specified as constant. Actually, it is proportional to n, but there are no invocations of value_type constructors or other value_type operations.

For the iterator-based constructor the complexity should be:

Complexity: exactly n calls to construct value_type from InputIterator::value_type (where n = distance(f,l)). The number of calls to key_equal::operator() is proportional to n in the average case and n*n in the worst case.

[ 2010 Rapperswil: ]

Concern that the current wording may require O(1) where that cannot be delivered. We need to look at both the clause 23 requirements tables and the constructor description of each unordered container to be sure.

Howard suggests NAD Editorial as we updated the container requirement tables since this issue was written.

Daniel offers to look deeper, and hopefully produce wording addressing any outstanding concerns at the next meeting.

Move to Open.

[2011-02-26: Daniel provides wording]

I strongly suggest to clean-up the differences between requirement tables and individual specifications. In the usual way, the most specific specifications wins, which is in this case the wrong one. In regard to the concern expressed about missing DefaultConstructible requirements of the value type I disagree: The function argument n is no size-control parameter, but only some effective capacity parameter: No elements will be value-initialized by these constructors. The necessary requirement for the value type, EmplaceConstructible into *this, is already listed in Table 103 — Unordered associative container requirements. Another part of the proposed resolution is the fact that there is an inconsistency of the complexity counting when both a range and a bucket count is involved compared to constructions where only bucket counts are provided: E.g. the construction X a(n); has a complexity of n bucket allocations, but this part of the work is omitted for X a(i, j, n);, even though it is considerable larger (in the average case) for n ≫ distance(i, j).

[2011-03-24 Madrid meeting]

Move to deferred

[ 2011 Bloomington ]

The proposed wording looks good. Move to Review.

[2012, Kona]

Fix up some presentation issues with the wording, combining the big-O expressions into single expressions rather than the sum of two separate big-Os.

Strike "constant or linear", prefer "linear in the number of buckets". This allows for number of buckets being larger than requested n as well.

Default n to "unspecified" rather than "implementation-defined". It seems an un-necessary burden asking vendors to document a quantity that is easily determined through the public API of these classes.

Replace distance(f,l) with "number of elements in the range [f,l)"

Retain in Review with the updated wording

[2012, Portland: Move to Open]

The wording still does not call out Pablo's original concern, that the element constructor is called no more than N times, and that the N squared term applies to moves during rehash.

Inconsistent use of O(n)+O(N) vs. O(n+N), with a preference for the former.

AJM to update wording with a reference to "no more than N element constructor calls".

Matt concerned that calling out the O(n) requirements is noise, and dangerous noise in suggesting a precision we do not mean. The cost of constructing a bucket is very different to constructing an element of user-supplied type.

AJM notes that if there are multiple rehashes, the 'n' complexity is probably not linear.

Matt suggests back to Open, Pablo suggests potentially NAD if we keep revisitting without achieving a resolution.

Matt suggests complexity we are concerned with is the number of operations, such as constructing elements, moving nodes, and comparing/hashing keys. We are less concerned with constructing buckets, which are generally noise in this bigger picture.

Proposed resolution:

  1. Modify the following rows in Table 103 — Unordered associative container requirements to add the explicit bucket allocation overhead of some constructions. As editorial recommendation it is suggested not to shorten the sum 𝒪(n) + 𝒪(N) to 𝒪(n + N), because two different work units are involved.

    Table 103 — Unordered associative container requirements (in addition to container)
    Expression Return type Assertion/note pre-/post-condition Complexity
    X(i, j, n, hf, eq)
    X a(i, j, n, hf, eq)
    X
    Effects: Constructs an empty container with at least n
    buckets, using hf as the hash function and eq as the key
    equality predicate, and inserts elements from [i, j) into it.
    Average case 𝒪(n + N) (N is distance(i, j)),
    worst case 𝒪(n) + 𝒪(N2)
    X(i, j, n, hf)
    X a(i, j, n, hf)
    X
    Effects: Constructs an empty container with at least n
    buckets, using hf as the hash function and key_equal() as the key
    equality predicate, and inserts elements from [i, j) into it.
    Average case 𝒪(n + N) (N is distance(i, j)),
    worst case 𝒪(n + N2)
    X(i, j, n)
    X a(i, j, n)
    X
    Effects: Constructs an empty container with at least n
    buckets, using hasher() as the hash function and key_equal() as the key
    equality predicate, and inserts elements from [i, j) into it.
    Average case 𝒪(n + N) (N is distance(i, j)),
    worst case 𝒪(n + N2)
  2. Modify 23.5.4.2 [unord.map.cnstr] p. 1-4 as indicated (The edits of p. 1 and p. 3 attempt to fix some editorial oversight.):

    explicit unordered_map(size_type n = see below,
                           const hasher& hf = hasher(),
                           const key_equal& eql = key_equal(),
                           const allocator_type& a = allocator_type());
    

    1 Effects: Constructs an empty unordered_map using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_map. max_load_factor() returns 1.0.

    2 Complexity: ConstantLinear in the number of buckets.

    template <class InputIterator>
    unordered_map(InputIterator f, InputIterator l,
                  size_type n = see below,
                  const hasher& hf = hasher(),
                  const key_equal& eql = key_equal(),
                  const allocator_type& a = allocator_type());
    

    3 Effects: Constructs an empty unordered_map using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_map. Then inserts elements from the range [f, l). max_load_factor() returns 1.0.

    4 Complexity: Average case linear, worst case quadraticLinear in the number of buckets. In the average case linear in N and in the worst case quadratic in N to insert the elements, where N is equal to number of elements in the range [f,l).

  3. Modify 23.5.5.2 [unord.multimap.cnstr] p. 1-4 as indicated (The edits of p. 1 and p. 3 attempt to fix some editorial oversight.):

    explicit unordered_multimap(size_type n = see below,
                                const hasher& hf = hasher(),
                                const key_equal& eql = key_equal(),
                                const allocator_type& a = allocator_type());
    

    1 Effects: Constructs an empty unordered_multimap using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_multimap. max_load_factor() returns 1.0.

    2 Complexity: ConstantLinear in the number of buckets.

    template <class InputIterator>
    unordered_multimap(InputIterator f, InputIterator l,
                       size_type n = see below,
                       const hasher& hf = hasher(),
                       const key_equal& eql = key_equal(),
                       const allocator_type& a = allocator_type());
    

    3 Effects: Constructs an empty unordered_multimap using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_multimap. Then inserts elements from the range [f, l). max_load_factor() returns 1.0.

    4 Complexity: Average case linear, worst case quadraticLinear in the number of buckets. In the average case linear in N and in the worst case quadratic in N to insert the elements, where N is equal to number of elements in the range [f,l).

  4. Modify 23.5.6.2 [unord.set.cnstr] p. 1-4 as indicated (The edits of p. 1 and p. 3 attempt to fix some editorial oversight.):

    explicit unordered_set(size_type n = see below,
                           const hasher& hf = hasher(),
                           const key_equal& eql = key_equal(),
                           const allocator_type& a = allocator_type());
    

    1 Effects: Constructs an empty unordered_set using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_set. max_load_factor() returns 1.0.

    2 Complexity: ConstantLinear in the number of buckets.

    template <class InputIterator>
    unordered_set(InputIterator f, InputIterator l,
                  size_type n = see below,
                  const hasher& hf = hasher(),
                  const key_equal& eql = key_equal(),
                  const allocator_type& a = allocator_type());
    

    3 Effects: Constructs an empty unordered_set using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_set. Then inserts elements from the range [f, l). max_load_factor() returns 1.0.

    4 Complexity: Average case linear, worst case quadraticLinear in the number of buckets. In the average case linear in N and in the worst case quadratic in N to insert the elements, where N is equal to number of elements in the range [f,l).

  5. Modify 23.5.7.2 [unord.multiset.cnstr] p. 1-4 as indicated (The edits of p. 1 and p. 3 attempt to fix some editorial oversight.):

    explicit unordered_multiset(size_type n = see below,
                                const hasher& hf = hasher(),
                                const key_equal& eql = key_equal(),
                                const allocator_type& a = allocator_type());
    

    1 Effects: Constructs an empty unordered_multiset using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_multiset. max_load_factor() returns 1.0.

    2 Complexity: ConstantLinear in the number of buckets.

    template <class InputIterator>
    unordered_multiset(InputIterator f, InputIterator l,
                       size_type n = see below,
                       const hasher& hf = hasher(),
                       const key_equal& eql = key_equal(),
                       const allocator_type& a = allocator_type());
    

    3 Effects: Constructs an empty unordered_multiset using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is unspecifiedimpldefdefault number of buckets in unordered_multiset. Then inserts elements from the range [f, l). max_load_factor() returns 1.0.

    4 Complexity: Average case linear, worst case quadraticLinear in the number of buckets. In the average case linear in N and in the worst case quadratic in N to insert the elements, where N is equal to number of elements in the range [f,l).


1213. Meaning of valid and singular iterator underspecified

Section: 24.2 [iterator.requirements] Status: Deferred Submitter: Daniel Krügler Opened: 2009-09-19 Last modified: 2012-11-14

View all other issues in [iterator.requirements].

View all issues with Deferred status.

Discussion:

The terms valid iterator and singular aren't properly defined. The fuzziness of those terms became even worse after the resolution of 208 (including further updates by 278). In 24.2 [iterator.requirements] as of N2723 the standard says now:

5 - These values are called past-the-end values. Values of an iterator i for which the expression *i is defined are called dereferenceable. The library never assumes that past-the-end values are dereferenceable. Iterators can also have singular values that are not associated with any container. [...] Results of most expressions are undefined for singular values; the only exceptions are destroying an iterator that holds a singular value and the assignment of a non-singular value to an iterator that holds a singular value. [...] Dereferenceable values are always non-singular.

10 - An invalid iterator is an iterator that may be singular.

First, issue 208 intentionally removed the earlier constraint that past-the-end values are always non-singular. The reason for this was to support null pointers as past-the-end iterators of e.g. empty sequences. But there seem to exist different views on what a singular (iterator) value is. E.g. according to the SGI definition a null pointer is not a singular value:

Dereferenceable iterators are always nonsingular, but the converse is not true. For example, a null pointer is nonsingular (there are well defined operations involving null pointers) even thought it is not dereferenceable.

and proceeds:

An iterator is valid if it is dereferenceable or past-the-end.

Even if the standard prefers a different meaning of singular here, the change was incomplete, because by restricting feasible expressions of singular iterators to destruction and assignment isn't sufficient for a past-the-end iterator: Of-course it must still be equality-comparable and in general be a readable value.

Second, the standard doesn't clearly say whether a past-the-end value is a valid iterator or not. E.g. 20.7.12 [specialized.algorithms]/1 says:

In all of the following algorithms, the formal template parameter ForwardIterator is required to satisfy the requirements of a forward iterator (24.1.3) [..], and is required to have the property that no exceptions are thrown from [..], or dereference of valid iterators.

The standard should make better clear what "singular pointer" and "valid iterator" means. The fact that the meaning of a valid value has a core language meaning doesn't imply that for an iterator concept the term "valid iterator" has the same meaning.

Let me add a final example: In X [allocator.concepts.members] of N2914 we find:

pointer X::allocate(size_type n);

11 Returns: a pointer to the allocated memory. [Note: if n == 0, the return value is unspecified. —end note]

[..]

void X::deallocate(pointer p, size_type n);

Preconditions: p shall be a non-singular pointer value obtained from a call to allocate() on this allocator or one that compares equal to it.

If singular pointer value would include null pointers this make the preconditions unclear if the pointer value is a result of allocate(0): Since the return value is unspecified, it could be a null pointer. Does that mean that programmers need to check the pointer value for a null value before calling deallocate?

[ 2010-11-09 Daniel comments: ]

A later paper is in preparation.

[ 2010 Batavia: ]

Doesn't need to be resolved for Ox

Proposed resolution:

Consider to await the paper.


1450. Contradiction in regex_constants

Section: 28.5.2 [re.matchflag] Status: Open Submitter: BSI Opened: 2010-08-25 Last modified: 2012-11-14

View all issues with Open status.

Discussion:

Addresses GB-127

The Bitmask Type requirements in 17.5.2.1.3 [bitmask.types] p.3 say that all elements on a bitmask type have distinct values, but 28.5.2 [re.matchflag] defines regex_constants::match_default and regex_constants::format_default as elements of the bitmask type regex_constants::match_flag_type, both with value 0. This is a contradiction.

[ Resolution proposed by ballot comment: ]

One of the bitmask elements should be removed from the declaration and should be defined separately, in the same manner as ios_base::adjustfield, ios_base::basefield and ios_base::floatfield are defined by 27.5.3.1.2 [ios::fmtflags] p.2 and Table 120. These are constants of a bitmask type, but are not distinct elements, they have more than one value set in the bitmask. regex_constants::format_default should be specified as a constant with the same value as regex_constants::match_default.

[ 2010-10-31 Daniel comments: ]

Strictly speaking, a bitmask type cannot have any element of value 0 at all, because any such value would contradict the requirement expressed in 17.5.2.1.3 [bitmask.types] p. 3:

for any pair Ci and Cj, Ci & Ci is nonzero

So, actually both regex_constants::match_default and regex_constants::format_default are only constants of the type regex_constants::match_flag_type, and no bitmask elements.

[ 2010-11-03 Daniel comments and provides a proposed resolution: ]

The proposed resolution is written against N3126 and considered as a further improvement of the fixes suggested by n3110.

Add the following sentence to 28.5.2 [re.matchflag] paragraph 1:

1 The type regex_constants::match_flag_type is an implementation-defined bitmask type (17.5.2.1.3). Matching a regular expression against a sequence of characters [first,last) proceeds according to the rules of the grammar specified for the regular expression object, modified according to the effects listed in Table 136 for any bitmask elements set. Type regex_constants::match_flag_type also defines the constants regex_constants::match_default and regex_constants::format_default.

[ 2011 Bloomington ]

It appears the key problem is the phrasing of the bitmask requirements. Jeremiah supplies updated wording.

Pete Becker has also provided an alternative resolution.

Ammend 17.5.2.1.3 [bitmask.types]:

Change the list of values for "enum bit mask" in p2 from

V0 = 1 << 0, V1 = 1 << 1, V2 = 1 << 2, V3 = 1 << 3, ....

to

V0 = 0, V1 = 1 << 0, V2 = 1 << 1, V3 = 1 << 2, ....

Here, the names C0, C1, etc. represent bitmask elements for this particular bitmask type. All such non-zero elements have distinct values such that, for any pair Ci and Cj where i != j, Ci & Ci is nonzero and Ci & Cj is zero.

Change bullet 3 of paragraph 4:

TheA non-zero value Y is set in the object X if the expression X & Y is nonzero.

Proposed resolution:

Ammend 17.5.2.1.3 [bitmask.types] p3:

Here, the names C0, C1, etc. represent bitmask elements for this particular bitmask type. All such elements have distinct, non-zero values such that, for any pair Ci and Cj where i != j, Ci & Ci is nonzero and Ci & Cj is zero. Additionally, the value 0 is used to represent an empty bitmask, in which no bitmask elements are set.

Add the following sentence to 28.5.2 [re.matchflag] paragraph 1:

1 The type regex_constants::match_flag_type is an implementation-defined bitmask type (17.5.2.1.3). The constants of that type, except for match_default and format_default, are bitmask elements. The match_default and format_default constants are empty bitmasks. Matching a regular expression against a sequence of characters [first,last) proceeds according to the rules of the grammar specified for the regular expression object, modified according to the effects listed in Table 136 for any bitmask elements set.


1526. C++ should not impose thread safety requirements on C99 library implementations

Section: 17.6.5.9 [res.on.data.races] Status: Open Submitter: BSI Opened: 2011-03-24 Last modified: 2013-10-15

View all issues with Open status.

Discussion:

Addresses GB-111

Section 17.6.5.9 [res.on.data.races], Data Race Avoidance, requires the C++ Standard Library to avoid data races that might otherwise result from two threads making calls to C++ Standard Library functions on distinct objects. The C standard library is part of the C++ Standard Library and some C++ Standary library functions (parts of the Localization library, as well as Numeric Conversions in 21.5), are specified to make use of the C standard library. Therefore, the C++ standard indirectly imposes a requirement on the thread safety of the C standard library. However, since the C standard does not address the concept of thread safety conforming C implementations exist that do no provide such guarantees. This conflict needs to be reconciled.

Suggested resolution by national body comment:

remove the requirement to make use of strtol() and sprintf() since these functions depend on the global C locale and thus cannot be made thread safe.

[2011-03-24 Madrid meeting]

Deferred

[ 2011 Bloomington ]

Alisdair: PJ, does this cause a problem in C?

PJ: Every implementation know of is thread safe.

Pete: There a couple of effects that are specified on strtol() and sprintf() which is a problem.

PJ: When C++ talks about C calls it should be "as if" calling the function.

Pete: Culprit is to string stuff. My fault.

PJ: Not your fault. You did what you were told. Distinct resolution to change wording.

Dietmar: What would we break if we change it back?

Pete: Nothing. If implemented on top of thread safe C library you are just fine.

Alisdair: Anyone want to clean up wording and put it back to what Pete gave us?

Alisdair: No volunteers. Do we want to mark as NAD? We could leave it as deferred.

Stefanus: Did original submitter care about this?

Lawrence: There is some work to make local calls thread safe. The resolution would be to call those thread safe version.

Pete: "As if called under single threaded C program"

Action Item (Alisdair): Write wording for this issue.

[2012, Kona]

Re-opened at the request of the concurrency subgroup, who feel there is an issue that needs clarifying for the (planned) 2017 standard.

Rationale:

No consensus to make a change at this time

[2012, Portland]

The concurrency subgroup decided to encourage the LWG to consider a change to 17.2 [library.c] or thereabouts to clarify that we are requiring C++-like thread-safety for setlocale, so that races are not introduced by C locale accesses, even when the C library allows it. This would require e.g. adding "and data race avoidance" at the end of 17.2 [library.c] p1:

"The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety and data race avoidance.",

with some further clarifications in the sections mentioned in 1526.

This seems to be consistent with existing implementations. This would technically not be constraining C implementation, but it would be further constraining C libraries used for both C and C++.

Proposed resolution:

This wording is relative to N3376.

  1. Change 17.2 [library.c] p1 as indicated:

    -1- The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety and data race avoidance.


2003. String exception inconsistency in erase.

Section: 21.4.1 [string.require] Status: Open Submitter: José Daniel García Sánchez Opened: 2010-10-21 Last modified: 2012-11-14

View other active issues in [string.require].

View all other issues in [string.require].

View all issues with Open status.

Discussion:

Clause 21.4.1 [string.require]p3 states:

No erase() or pop_back() member function shall throw any exceptions.

However in 21.4.6.5 [string::erase] p2 the first version of erase has

Throws: out_of_range if pos > size().

[2011-03-24 Madrid meeting]

Beman: Don't want to just change this, can we just say "unless otherwise specified"?

Alisdair: Leave open, but update proposed resolution to say something like "unless otherwise specified".

General agreement that it should be corrected but not a stop-ship.

Action: Update proposed wording for issue 2003 as above, but leave Open.

Proposed resolution:

Update [string.require]p/3:

3 No erase() or pop_back() member function shall throw any exceptions.


2016. Allocators must be no-throw swappable

Section: 17.6.3.5 [allocator.requirements] Status: Open Submitter: Daniel Krügler Opened: 2010-11-17 Last modified: 2012-11-14

View other active issues in [allocator.requirements].

View all other issues in [allocator.requirements].

View all issues with Open status.

Discussion:

During the Batavia meeting it turned out that there is a definition hole for types satisfying the Allocators requirements: The problem became obvious when it was discussed whether all swap functions of Containers with internal data handles can be safely tagged with noexcept or not. While it is correct that the implicit swap function of an allocator is required to be a no-throw operation (because move/copy-constructors and assignment operators are required to be no-throw functions), there are no such requirements for specialized swap overloads for a particular allocator.

But this requirement is essential because the Containers are required to support swappable Allocators, when the value allocator_traits<>::propagate_on_container_swap evaluates to true.

[2011-02-10 Alberto, Daniel, and Pablo collaborated on the proposed wording]

The proposed resolution (based on N3225) attempts to solve the following problems:

  1. Table 44 — Allocator requirements, expression rows X::propagate_on_container_copy_assignment, X::propagate_on_container_move_assignment, and X::propagate_on_container_swap only describe operations, but no requirements. In fact, if and only if these compile-time predicates evaluate to true, the additional requirements CopyAssignable, no-throw MoveAssignable, and no-throw lvalue Swappable, respectively, are imposed on the allocator types.
  2. 23.2.1 [container.requirements.general] p. 9 misses to refer to the correct swap conditions: The current wording does not relate to 17.6.3.2 [swappable.requirements] as it should and omits to mention that lvalues shall be swapped. Additional there is one situation described twice in p. 8 and p. 9 (undefined behaviour unless a.get_allocator() == b.get_allocator() or allocator_traits<allocator_type>::propagate_on_container_swap::value == true), which should be cleaned up.

[2011-04-08 Pablo comments]

I'm implementing a version of list now and I actually do find it impossible to write an exception-safe assignment operator unless I can assume that allocator assignment does not throw. (The problem is that I use a sentinel node and I need to allocate a new sentinel using the new allocator without destroying the old one -- then swap the allocator and sentinel pointer in atomically, without risk of an exception leaving one inconsistent with the other.

Please update the proposed resolution to add the nothrow requirement to copy-assignment.

Proposed resolution:

  1. Adapt the following three rows from Table 44 — Allocator requirements:

    Table 44 — Allocator requirements
    Expression Return type Assertion/note
    pre-/post-condition
    Default
    X::propagate_on_container_copy_assignment Identical to or derived from true_type
    or false_type
    true_type only if an allocator of type X should be copied
    when the client container is copy-assigned. See Note B, below.
    false_type
    X::propagate_on_container_move_assignment Identical to or derived from true_type
    or false_type
    true_type only if an allocator of type X should be moved
    when the client container is move-assigned. See Note B, below.
    false_type
    X::propagate_on_container_swap Identical to or derived from true_type
    or false_type
    true_type only if an allocator of type X should be swapped
    when the client container is swapped. See Note B, below.
    false_type
  2. Following 17.6.3.5 [allocator.requirements] p. 3 insert a new normative paragraph:

    Note B: If X::propagate_on_container_copy_assignment::value is true, X shall satisfy the CopyAssignable requirements (Table 39 [copyassignable]) and the copy operation shall not throw exceptions. If X::propagate_on_container_move_assignment::value is true, X shall satisfy the MoveAssignable requirements (Table 38 [moveassignable]) and the move operation shall not throw exceptions. If X::propagate_on_container_swap::value is true, lvalues of X shall be swappable (17.6.3.2 [swappable.requirements]) and the swap operation shall not throw exceptions.

  3. Modify 23.2.1 [container.requirements.general] p. 8 and p. 9 as indicated:

    8 - [..] The allocator may be replaced only via assignment or swap(). Allocator replacement is performed by copy assignment, move assignment, or swapping of the allocator only if allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value, allocator_traits<allocator_type>::propagate_on_container_move_assignment::value, or allocator_traits<allocator_type>::propagate_on_container_swap::value is true within the implementation of the corresponding container operation. The behavior of a call to a container's swap function is undefined unless the objects being swapped have allocators that compare equal or allocator_traits<allocator_type>::propagate_on_container_swap::value is true. In all container types defined in this Clause, the member get_allocator() returns a copy of the allocator used to construct the container or, if that allocator has been replaced, a copy of the most recent replacement.

    9 - The expression a.swap(b), for containers a and b of a standard container type other than array, shall exchange the values of a and b without invoking any move, copy, or swap operations on the individual container elements. Lvalues of aAny Compare, Pred, or Hash objects belonging to a and b shall be swappable and shall be exchanged by unqualified calls to non-member calling swap as described in 17.6.3.2 [swappable.requirements]. If allocator_traits<allocator_type>::propagate_on_container_swap::value is true, then lvalues of allocator_type shall be swappable and the allocators of a and b shall also be exchanged using a an unqualified call to non-member swap call as described in 17.6.3.2 [swappable.requirements]. Otherwise, theythe allocators shall not be swapped, and the behavior is undefined unless a.get_allocator() == b.get_allocator(). Every iterator referring to an element in one container before the swap shall refer to the same element in the other container after the swap. It is unspecified whether an iterator with value a.end() before the swap will have value b.end() after the swap.


2035. Output iterator requirements are broken

Section: 24.2.4 [output.iterators] Status: Open Submitter: Daniel Krügler Opened: 2011-02-27 Last modified: 2012-11-14

View other active issues in [output.iterators].

View all other issues in [output.iterators].

View all issues with Open status.

Discussion:

During the Pittsburgh meeting the proposal N3066 became accepted because it fixed several severe issues related to the iterator specification. But the current working draft (N3225) does not reflect all these changes. Since I'm unaware whether every correction can be done editorial, this issue is submitted to take care of that. To give one example: All expressions of Table 108 — "Output iterator requirements" have a post-condition that the iterator is incrementable. This is impossible, because it would exclude any finite sequence that is accessed by an output iterator, such as a pointer to a C array. The N3066 wording changes did not have these effects.

[2011-03-01: Daniel comments:]

This issue has some overlap with the issue 2038 and I would prefer if we could solve both at one location. I suggest the following approach:

  1. The terms dereferencable and incrementable could be defined in a more general way not restricted to iterators (similar to the concepts HasDereference and HasPreincrement from working draft N2914). But on the other hand, all current usages of dereferencable and incrementable are involved with types that satisfy iterator requirements. Thus, I believe that it is sufficient for C++0x to add corresponding definitions to 24.2.1 [iterator.requirements.general] and to let all previous usages of these terms refer to this sub-clause. Since the same problem occurs with the past-the-end iterator, this proposal suggest providing similar references to usages that precede its definition as well.

  2. We also need to ensure that all iterator expressions get either an operational semantics in terms of others or we need to add missing pre- and post-conditions. E.g. we have the following ones without semantics:

    *r++ = o // output iterator
    *r--     // bidirectional iterator
    

    According to the SGI specification these correspond to

    { *r = o; ++r; }                         // output iterator
    { reference tmp = *r; --r; return tmp; } // bidirectional iterator
    

    respectively. Please note especially the latter expression for bidirectional iterator. It fixes a problem that we have for forward iterator as well: Both these iterator categories provide stronger guarantees than input iterator, because the result of the dereference operation is reference, and not only convertible to the value type (The exact form from the SGI documentation does not correctly refer to reference).

[2011-03-14: Daniel comments and updates the suggested wording]

In addition to the before mentioned necessary changes there is another one need, which became obvious due to issue 2042: forward_list<>::before_begin() returns an iterator value which is not dereferencable, but obviously the intention is that it should be incrementable. This leads to the conclusion that imposing dereferencable as a requirement for the expressions ++r is wrong: We only need the iterator to be incrementable. A similar conclusion applies to the expression --r of bidirectional iterators.

[ 2011 Bloomington ]

Consensus this is the correct direction, but there are (potentially) missing incrementable preconditions on some table rows, and the Remarks on when an output iterator becomes dereferencable are probably better handled outside the table, in a manner similar to the way we word for input iterators.

There was some concern about redundant pre-conditions when the operational semantic is defined in terms of operations that have preconditions, and a similar level of concern over dropping such redundancies vs. applying a consistent level of redundant specification in all the iterator tables. Wording clean-up in either direction would be welcome.

[2011-08-18: Daniel adapts the proposed resolution to honor the Bloomington request]

There is only a small number of further changes suggested to get rid of superfluous requirements and essentially non-normative assertions. Operations should not have extra pre-conditions, if defined by "in-terms-of" semantics, see e.g. a != b or a->m for Table 107. Further, some remarks, that do not impose anything or say nothing new have been removed, because I could not find anything helpful they provide. E.g. consider the remarks for Table 108 for the operations dereference-assignment and preincrement: They don't provide additional information say nothing surprising. With the new pre-conditions and post-conditions it is implied what the remarks intend to say.

[ 2011-11-03: Some observations from Alexander Stepanov via c++std-lib-31405 ]

The following sentence is dropped from the standard section on OutputIterators:

"In particular, the following two conditions should hold: first, any iterator value should be assigned through before it is incremented (this is, for an output iterator i, i++; i++; is not a valid code sequence); second, any value of an output iterator may have at most one active copy at any given time (for example, i = j; *++i = a; *j = b; is not a valid code sequence)."

[ 2011-11-04: Daniel comments and improves the wording ]

In regard to the first part of the comment, the intention of the newly proposed wording was to make clear that for the expression

*r = o

we have the precondition dereferenceable and the post-condition incrementable. And for the expression

++r

we have the precondition incrementable and the post-condition dereferenceable or past-the-end. This should not allow for a sequence like i++; i++; but I agree that it doesn't exactly say that.

In regard to the second point: To make this point clearer, I suggest to add a similar additional wording as we already have for input iterator to the "Assertion/note" column of the expression ++r:

"Post: any copies of the previous value of r are no longer required to be dereferenceable or incrementable."

The proposed has been updated to honor the observations of Alexander Stepanov.

Proposed resolution:

  1. Add a reference to 24.2.1 [iterator.requirements.general] to the following parts of the library preceding Clause 24 Iterators library: (I stopped from 23.2.5 [unord.req] on, because the remaining references are the concrete containers)

    1. 17.6.3.2 [swappable.requirements] p5:

      -5- A type X satisfying any of the iterator requirements (24.2) is ValueSwappable if, for any dereferenceable (24.2.1 [iterator.requirements.general]) object x of type X, *x is swappable.

    2. 17.6.3.5 [allocator.requirements], Table 27 — "Descriptive variable definitions", row with the expression c:

      a dereferenceable (24.2.1 [iterator.requirements.general]) pointer of type C*

    3. 20.7.3.2 [pointer.traits.functions]:

      Returns: The first template function returns a dereferenceable (24.2.1 [iterator.requirements.general]) pointer to r obtained by calling Ptr::pointer_to(r); […]

    4. 21.4.3 [string.iterators] p. 2:

      Returns: An iterator which is the past-the-end value (24.2.1 [iterator.requirements.general]).

    5. 22.4.5.1.2 [locale.time.get.virtuals] p. 11:

      iter_type do_get(iter_type s, iter_type end, ios_base& f,
        ios_base::iostate& err, tm *t, char format, char modifier) const;
      

      Requires: t shall be dereferenceable (24.2.1 [iterator.requirements.general]).

    6. 23.2.1 [container.requirements.general] p. 6:

      […] end() returns an iterator which is the past-the-end (24.2.1 [iterator.requirements.general]) value for the container. […]

    7. 23.2.3 [sequence.reqmts] p. 3:

      […] q denotes a valid dereferenceable (24.2.1 [iterator.requirements.general]) const iterator to a, […]

    8. 23.2.4 [associative.reqmts] p. 8 (I omit intentionally one further reference in the same sub-clause):

      […] q denotes a valid dereferenceable (24.2.1 [iterator.requirements.general]) const iterator to a, […]

    9. 23.2.5 [unord.req] p. 10 (I omit intentionally one further reference in the same sub-clause):

      […] q and q1 are valid dereferenceable (24.2.1 [iterator.requirements.general]) const iterators to a, […]

  2. Edit 24.2.1 [iterator.requirements.general] p. 5 as indicated (The intent is to properly define incrementable and to ensure some further library guarantee related to past-the-end iterator values):

    -5- Just as a regular pointer to an array guarantees that there is a pointer value pointing past the last element of the array, so for any iterator type there is an iterator value that points past the last element of a corresponding sequence. These values are called past-the-end values. Values of an iterator i for which the expression *i is defined are called dereferenceable. Values of an iterator i for which the expression ++i is defined are called incrementable. The library never assumes that past-the-end values are dereferenceable or incrementable. Iterators can also have singular values that are not associated with any sequence. […]

  3. Modify the column contents of Table 106 — "Iterator requirements", 24.2.2 [iterator.iterators], as indicated:

    Table 106 — Iterator requirements
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    *r reference   pre: r is dereferenceable.
    ++r X&   pre: r is incrementable.
  4. Modify the column contents of Table 107 — "Input iterator requirements", 24.2.3 [input.iterators], as indicated [Rationale: The wording changes attempt to define a minimal "independent" set of operations, namely *a and ++r, and to specify the semantics of the remaining ones. This approach seems to be in agreement with the original SGI specificationend rationale]:

    Table 107 — Input iterator requirements (in addition to Iterator)
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    a != b contextually
    convertible to bool
    !(a == b) pre: (a, b) is in the domain
    of ==.
    *a convertible to T   pre: a is dereferenceable.
    The expression
    (void)*a, *a is equivalent
    to *a.
    If a == b and (a,b) is in
    the domain of == then *a is
    equivalent to *b.
    a->m   (*a).m pre: a is dereferenceable.
    ++r X&   pre: r is dereferenceableincrementable.
    post: r is dereferenceable or
    r is past-the-end.
    post: any copies of the
    previous value of r are no
    longer required either to be
    dereferenceable, incrementable,
    or to be in the domain of ==.
    (void)r++   (void)++r equivalent to (void)++r
    *r++ convertible to T { T tmp = *r;
    ++r;
    return tmp; }
     
  5. Modify the column contents of Table 108 — "Output iterator requirements", 24.2.4 [output.iterators], as indicated [Rationale: The wording changes attempt to define a minimal "independent" set of operations, namely *r = o and ++r, and to specify the semantics of the remaining ones. This approach seems to be in agreement with the original SGI specificationend rationale]:

    Table 108 — Output iterator requirements (in addition to Iterator)
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    *r = o result is not used   pre: r is dereferenceable.
    Remark: After this operation
    r is not required to be
    dereferenceable and any copies of
    the previous value of r are no
    longer required to be dereferenceable
    or incrementable.

    post: r is incrementable.
    ++r X&   pre: r is incrementable.
    &r == &++r.
    Remark: After this operation
    r is not required to be
    dereferenceable.
    Remark: After this operation
    r is not required to be
    incrementable and any copies of
    the previous value of r are no
    longer required to be dereferenceable
    or incrementable.

    post: r is dereferenceable
    or r is past-the-end
    incrementable.
    r++ convertible to const X& { X tmp = r;
    ++r;
    return tmp; }
    Remark: After this operation
    r is not required to be
    dereferenceable.
    post: r is incrementable.
    *r++ = o result is not used { *r = o; ++r; } Remark: After this operation
    r is not required to be
    dereferenceable.
    post: r is incrementable.
  6. Modify the column contents of Table 109 — "Forward iterator requirements", 24.2.5 [forward.iterators], as indicated [Rationale: Since the return type of the expression *r++ is now guaranteed to be type reference, the implied operational semantics from input iterator based on value copies is wrong — end rationale]

    Table 109 — Forward iterator requirements (in addition to input iterator)
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    r++ convertible to const X& { X tmp = r;
    ++r;
    return tmp; }
     
    *r++ reference { reference tmp = *r;
    ++r;
    return tmp; }
     
  7. Modify the column contents of Table 110 — "Bidirectional iterator requirements", 24.2.6 [bidirectional.iterators], as indicated:

    Table 110 — Bidirectional iterator requirements (in addition to forward iterator)
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    --r X&   pre: there exists s such that
    r == ++s.
    post: r is dereferenceableincrementable.
    --(++r) == r.
    --r == --s implies r == s.
    &r == &--r.
    r-- convertible to const X& { X tmp = r;
    --r;
    return tmp; }
     
    *r-- reference { reference tmp = *r;
    --r;
    return tmp; }
     

2038. Missing definition for incrementable iterator

Section: 24.2.4 [output.iterators] Status: Open Submitter: Pete Becker Opened: 2011-02-27 Last modified: 2012-11-14

View other active issues in [output.iterators].

View all other issues in [output.iterators].

View all issues with Open status.

Discussion:

In comp.lang.c++, Vicente Botet raises the following questions:

"In "24.2.4 Output iterators" there are 3 uses of incrementable. I've not found the definition. Could some one point me where it is defined?

Something similar occurs with dereferenceable. While the definition is given in "24.2.1 In general" it is used several times before.

Shouldn't these definitions be moved to some previous section?"

He's right: both terms are used without being properly defined.

There is no definition of "incrementable".

While there is a definition of "dereferenceable", it is, in fact, a definition of "dereferenceable iterator". "dereferenceable" is used throughout Clause 23 (Containers) before its definition in Clause 24. In almost all cases it's referring to iterators, but in 17.6.3.2 [swappable.requirements] there is a mention of "dereferenceable object"; in 17.6.3.5 [allocator.requirements] the table of Descriptive variable definitions refers to a "dereferenceable pointer"; 20.7.3.2 [pointer.traits.functions] refers to a "dereferenceable pointer"; in 22.4.5.1.2 [locale.time.get.virtuals]/11 (do_get) there is a requirement that a pointer "shall be dereferenceable". In those specific cases it is not defined.

[2011-03-02: Daniel comments:]

I believe that the currently proposed resolution of issue 2035 solves this issue as well.

[ 2011 Bloomington ]

Agree with Daniel, this will be handled by the resolution of 2035.

Proposed resolution:


2051. Explicit tuple constructors for more than one parameter

Section: 20.4.2 [tuple.tuple], 20.4.2.1 [tuple.cnstr] Status: Open Submitter: Ville Voutilainen Opened: 2011-05-01 Last modified: 2012-11-14

View all other issues in [tuple.tuple].

View all issues with Open status.

Discussion:

One of my constituents wrote the following:

-------snip------------

So far the only use I've found for std::tuple is as an ad-hoc type to emulate multiple return values. If the tuple ctor was made non-explicit one could almost think C++ supported multiple return values especially when combined with std::tie().

// assume types line_segment and point
// assume function double distance(point const&, point const&)

std::tuple<point, point>
closest_points(line_segment const& a, line_segment const& b) {
 point ax;
 point bx;
 /* some math */

 return {ax, bx};
}


double
distance(line_segment const& a, line_segment const& b) {
 point ax;
 point bx;
 std::tie(ax, bx) = closest_points(a, b);

 return distance(ax, bx);
}

-------snap----------

See also the messages starting from lib-29330.

Some notes:

  1. pair allows such a return
  2. a lambda with a deduced return type doesn't allow it for any type
  3. decltype refuses {1, 2}

I would recommend making non-unary tuple constructors non-explicit.

[Bloomington, 2011]

Move to NAD Future, this would be an extension to existing functionality.

[Portland, 2012]

Move to Open at the request of the Evolution Working Group.

Proposed resolution:


2052. Mixup between mapped_type and value_type for associative containers

Section: 23.2.4 [associative.reqmts] Status: Open Submitter: Marc Glisse Opened: 2011-05-04 Last modified: 2012-11-14

View other active issues in [associative.reqmts].

View all other issues in [associative.reqmts].

View all issues with Open status.

Discussion:

(this is basically reopening the first part of issue 2006, as discussed in the thread starting at c++std-lib-30698 )

Section 23.2.4 [associative.reqmts]

In Table 102, several uses of T (which means mapped_type here) should be value_type instead. This is almost editorial. For instance:

a_uniq.emplace(args)

Requires: T shall be EmplaceConstructible into X from args.

Effects: Inserts a T object t constructed with std::forward<Args>(args)... if and only if there is no element in the container with key equivalent to the key of t. The bool component of the returned pair is true if and only if the insertion takes place, and the iterator component of the pair points to the element with key equivalent to the key of t.

[ 2011 Bloomington ]

Not even an exhaustive list of problem locations. No reason to doubt issue.

Pablo agrees to provide wording.

[ 2011-09-04 Pablo Halpern provides improved wording ]

Proposed resolution:

In both section 23.2.4 [associative.reqmts] Table 102 and 23.2.5 [unord.req], Table 103, make the following text replacements:

Original text, in FDIS Replacement text
T is CopyInsertable into X and CopyAssignable. value_type is CopyInsertable into X, key_type is CopyAssignable, and mapped_type is CopyAssignable (for containers having a mapped_type)
T is CopyInsertable value_type is CopyInsertable
T shall be CopyInsertable value_type shall be CopyInsertable
T shall be MoveInsertable value_type shall be MoveInsertable
T shall be EmplaceConstructible value_type shall be EmplaceConstructible
T object value_type object

[ Notes to the editor: The above are carefully selected phrases that can be used for global search-and-replace within the specified sections without accidentally making changes to correct uses T. ]


2059. C++0x ambiguity problem with map::erase

Section: 23.4.4 [map] Status: Open Submitter: Christopher Jefferson Opened: 2011-05-18 Last modified: 2013-10-15

View all other issues in [map].

View all issues with Open status.

Discussion:

map::erase (and several related methods) took an iterator in C++03, but take a const_iterator in C++0x. This breaks code where the map's key_type has a constructor which accepts an iterator (for example a template constructor), as the compiler cannot choose between erase(const key_type&) and erase(const_iterator).

#include <map>

struct X
{
  template<typename T>
  X(T&) {}
};

bool operator<(const X&, const X&) { return false; }

void erasor(std::map<X,int>& s, X x)
{
  std::map<X,int>::iterator it = s.find(x);
  if (it != s.end())
    s.erase(it);
}

[ 2011 Bloomington ]

This issue affects only associative container erase calls, and is not more general, as these are the only functions that are also overloaded on another single arguement that might cause confusion - the erase by key method. The complete resolution should simply restore the iterator overload in addition to the const_iterator overload for all eight associative containers.

Proposed wording supplied by Alan Talbot, and moved to Review.

[2012, Kona]

Moved back to Open by post-meeting issues processing group.

Pablo very unhappy about case of breaking code with ambiguous conversion between both iterator types.

Alisdair strongly in favor of proposed resolution, this change from C++11 bit Chris in real code, and it took a while to track down the cause.

Move to open, bring in front of a larger group

Proposed wording from Jeremiah: erase(key) shall not participate in overload resolution if iterator is convertible to key. Note that this means making erase(key) a template-method

Poll Chris to find out if he already fixed his code, or fixed his library

Jeremiah - allow both overloads, but enable_if the const_iterator form as a template, requiring is_same to match only const_iterator.

Poll PJ to see if he has already applied this fix?

Proposed resolution:

Editorial note: The following things are different between 23.2.4 [associative.reqmts] p.8 and 23.2.5 [unord.req] p.10. These should probably be reconciled.

  1. First uses the convention "denotes"; second uses the convention "is".
  2. First redundantly says: "If no such element exists, returns a.end()." in erase table entry, second does not.

23.2.4 [associative.reqmts] Associative containers

8 In Table 102, X denotes an associative container class, a denotes a value of X, a_uniq denotes a value of X when X supports unique keys, a_eq denotes a value of X when X supports multiple keys, u denotes an identifier, i and j satisfy input iterator requirements and refer to elements implicitly convertible to value_type, [i,j) denotes a valid range, p denotes a valid const iterator to a, q denotes a valid dereferenceable const iterator to a, r denotes a valid dereferenceable iterator to a, [q1, q2) denotes a valid range of const iterators in a, il designates an object of type initializer_list<value_type>, t denotes a value of X::value_type, k denotes a value of X::key_type and c denotes a value of type X::key_compare. A denotes the storage allocator used by X, if any, or std::allocator<X::value_type> otherwise, and m denotes an allocator of a type convertible to A.

23.2.4 [associative.reqmts] Associative containers Table 102

Add row:

a.erase(r) iterator erases the element pointed to by r. Returns an iterator pointing to the element immediately following r prior to the element being erased. If no such element exists, returns a.end(). amortized constant

23.2.5 [unord.req] Unordered associative containers

10 In table 103: X is an unordered associative container class, a is an object of type X, b is a possibly const object of type X, a_uniq is an object of type X when X supports unique keys, a_eq is an object of type X when X supports equivalent keys, i and j are input iterators that refer to value_type, [i, j) is a valid range, p and q2 are valid const iterators to a, q and q1 are valid dereferenceable const iterators to a, r is a valid dereferenceable iterator to a, [q1,q2) is a valid range in a, il designates an object of type initializer_list<value_type>, t is a value of type X::value_type, k is a value of type key_type, hf is a possibly const value of type hasher, eq is a possibly const value of type key_equal, n is a value of type size_type, and z is a value of type float.

23.2.5 [unord.req] Unordered associative containers Table 103

Add row:

a.erase(r) iterator Erases the element pointed to by r. Returns the iterator immediately following r prior to the erasure. Average case O(1), worst case O(a.size()).

23.4.4.1 [map.overview] Class template map overview p. 2

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

23.4.5.1 [multimap.overview] Class template multimap overview p. 2

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

23.4.6.1 [set.overview] Class template set overview p. 2

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

23.4.7.1 [multiset.overview] Class template multiset overview

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

23.5.4.1 [unord.map.overview] Class template unordered_map overview p. 3

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

23.5.5.1 [unord.multimap.overview] Class template unordered_multimap overview p. 3

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

23.5.6.1 [unord.set.overview] Class template unordered_set overview p. 3

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

23.5.7.1 [unord.multiset.overview] Class template unordered_multiset overview p. 3

iterator erase(iterator position);
iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

C.2.13 [diff.cpp03.containers] C.2.12 Clause 23: containers library

23.2.3, 23.2.4

Change: Signature changes: from iterator to const_iterator parameters

Rationale: Overspecification. Effects: The signatures of the following member functions changed from taking an iterator to taking a const_iterator:

Valid C++ 2003 code that uses these functions may fail to compile with this International Standard.


2062. Effect contradictions w/o no-throw guarantee of std::function swaps

Section: 20.9.11.2 [func.wrap.func], 20.9.11.2.2 [func.wrap.func.mod] Status: Open Submitter: Daniel Krügler Opened: 2011-05-28 Last modified: 2012-11-14

View all other issues in [func.wrap.func].

View all issues with Open status.

Discussion:

Howard Hinnant observed in reflector message c++std-lib-30841 that 20.9.11.2 [func.wrap.func] makes the member swap noexcept, even though the non-member swap is not noexcept.

The latter was an outcome of the discussions during the Batavia meeting and the Madrid meeting involving LWG 1349, which seems to indicate that the remaining noexcept specifier at the member swap is incorrect and should be removed.

But if we allow for a potentially throwing member swap of std::function, this causes another conflict with the exception specification for the following member function:

template<class F> function& operator=(reference_wrapper<F> f) noexcept;

Effects: function(f).swap(*this);

Note that in this example the sub-expression function(f) does not cause any problems, because of the nothrow-guarantee given in 20.9.11.2.1 [func.wrap.func.con] p. 10. The problem is located in the usage of the swap which could potentially throw given the general latitude.

So, either the Madrid meeting decision need to be revised (and both member and free swap of std::function should be noexcept), or this function needs to be adapted as well, e.g. by taking the exception-specification away or by changing the semantics.

One argument for "swap-may-throw" would be to allow for small-object optimization techniques where the copy of the target may throw. But given the fact that the swap function has been guaranteed to be "Throws: Nothing" from TR1 on, it seems to me that that there would still be opportunities to perform small-object optimizations just restricted to the set of target copies that cannot throw.

In my opinion member swap of std::function has always been intended to be no-throw, because otherwise there would be no good technical reason to specify the effects of several member functions in terms of the "construct-swap" idiom (There are three functions that are defined this way), which provides the strong exception safety in this case. I suggest to enforce that both member swap and non-member swap of std::function are nothrow functions as it had been guaranteed since TR1 on.

[ 2011 Bloomington ]

Dietmar: May not be swappable in the first place.

Alisdair: This is wide contact. Then we should be taking noexcept off instead of putting it on. This is preferred resolution.

Pablo: This is bigger issue. Specification of assignment in terms of swap is suspect to begin with. It is over specification. How this was applied to string is a better example to work from.

Pablo: Two problems: inconsistency that should be fixed (neither should have noexcept), the other issues is that assignment should not be specified in terms of swap. There are cases where assignment should succeed where swap would fail. This is easier with string as it should follow container rules.

Action Item (Alisdair): There are a few more issues found to file.

Dave: This is because of allocators? The allocator makes this not work.

Howard: There is a type erased allocator in shared_ptr. There is a noexcept allocator in shared_ptr.

Pablo: shared_ptr is a different case. There are shared semantics and the allocator does move around. A function does not have shared semantics.

Alisdair: Function objects think they have unique ownership.

Howard: In function we specify semantics with copy construction and swap.

Action Item (Pablo): Write this up better (why assignment should not be defined in terms of swap)

Howard: Not having trouble making function constructor no throw.

Dietmar: Function must allocate memory.

Howard: Does not put stuff that will throw on copy or swap in small object optimization. Put those on heap. Storing allocator, but has to be no throw copy constructable.

Pablo: Are you allowed to or required to swap or move allocators in case or swap or move.

Dave: An allocator that is type erased should be different...

Pablo: it is

Dave: Do you need to know something about allocator types? But only at construction time.

Pablo: You could have allocators that are different types.

Dave: Swap is two ended operation.

Pablo: Opinion is that both have to say propagate on swap for them to swap.

John: It is not arbitrary. If one person says no. No is no.

Howard: Find noexcept swap to be very useful. Would like to move in that direction and bring container design along.

Dave: If you have something were allocator must not propagate you can detect that at construction time.

...

Pablo: Need to leave this open and discuss in smaller group.

Alisdair: Tried to add boost::any as TR2 proposal and ran into this issue. Only the first place where we run into issues with type erased allocators. Suggest we move it to open.

Action Item: Move to open.

Action Item (Pablo works with Howard and Daniel): Address the more fundamental issue (which may be multiple issues) and write up findings.

[ Original resolution: ]

This wording is relative to the FDIS.

  1. Modify the header <functional> synopsis in 20.9 [function.objects] as indicated:

    namespace std {
      […]
    
      template<class R, class... ArgTypes>
      void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
    
      […]
    }
    
  2. Modify the class template function synopsis in 20.9.11.2 [func.wrap.func] as indicated:

    namespace std {
      […]
    
      // [func.wrap.func.alg], specialized algorithms:
      template<class R, class... ArgTypes>
      void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
    
      […]
    }
    
  3. Modify 20.9.11.2.7 [func.wrap.func.alg] as indicated:

    template<class R, class... ArgTypes>
    void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
    

    -1- Effects: f1.swap(f2);

Proposed resolution:


2063. Contradictory requirements for string move assignment

Section: 21.4 [basic.string] Status: Open Submitter: Howard Hinnant Opened: 2011-05-29 Last modified: 2012-11-14

View other active issues in [basic.string].

View all other issues in [basic.string].

View all issues with Open status.

Discussion:

21.4.1 [string.require]/p4 says that basic_string is an "allocator-aware" container and behaves as described in 23.2.1 [container.requirements.general].

23.2.1 [container.requirements.general] describes move assignment in p7 and Table 99.

If allocator_traits<allocator_type>::propagate_on_container_move_assignment::value is false, and if the allocators stored in the lhs and rhs sides are not equal, then move assigning a string has the same semantics as copy assigning a string as far as resources are concerned (resources can not be transferred). And in this event, the lhs may have to acquire resources to gain sufficient capacity to store a copy of the rhs.

However 21.4.2 [string.cons]/p22 says:

basic_string<charT,traits,Allocator>&
operator=(basic_string<charT,traits,Allocator>&& str) noexcept;

Effects: If *this and str are not the same object, modifies *this as shown in Table 71. [Note: A valid implementation is swap(str). — end note ]

These two specifications for basic_string::operator=(basic_string&&) are in conflict with each other. It is not possible to implement a basic_string which satisfies both requirements.

Additionally assign from an rvalue basic_string is defined as:

basic_string& assign(basic_string&& str) noexcept;

Effects: The function replaces the string controlled by *this with a string of length str.size() whose elements are a copy of the string controlled by str. [ Note: A valid implementation is swap(str). — end note ]

It seems contradictory that this member can be sensitive to propagate_on_container_swap instead of propagate_on_container_move_assignment. Indeed, there is a very subtle chance for undefined behavior here: If the implementation implements this in terms of swap, and if propagate_on_container_swap is false, and if the two allocators are unequal, the behavior is undefined, and will likely lead to memory corruption. That's a lot to go wrong under a member named "assign".

[ 2011 Bloomington ]

Alisdair: Can this be conditional noexcept?

Pablo: We said we were not going to put in many conditional noexcepts. Problem is not allocator, but non-normative definition. It says swap is a valid operation which it is not.

Dave: Move assignment is not a critical method.

Alisdair: Was confusing assignment and construction.

Dave: Move construction is critical for efficiency.

Kyle: Is it possible to test for noexcept.

Alisdair: Yes, query the noexcept operator.

Alisdair: Agreed there is a problem that we cannot unconditionally mark these operations as noexcept.

Pablo: How come swap is not defined in alloc

Alisdair: It is in utility.

Pablo: Swap has a conditional noexcept. Is no throw move constructable, is no throw move assignable.

Pablo: Not critical for strings or containers.

Kyle: Why?

Pablo: They do not use the default swap.

Dave: Important for deduction in other types.

Alisdair: Would change the policy we adopted during FDIS mode.

Pablo: Keep it simple and get some vendor experience.

Alisdair: Is this wording correct? Concerned with bullet 2.

Pablo: Where does it reference containers section.

Alisdair: String is a container.

Alisdair: We should not remove redundancy piecemeal.

Pablo: I agree. This is a deviation from rest of string. Missing forward reference to containers section.

Pablo: To fix section 2. Only the note needs to be removed. The rest needs to be a forward reference to containers.

Alisdair: That is a new issue.

Pablo: Not really. Talking about adding one sentence, saying that basic string is a container.

Dave: That is not just a forward reference, it is a semantic change.

PJ: We intended to make it look like a container, but it did not satisfy all the requirements.

Pablo: Clause 1 is correct. Clause 2 is removing note and noexcept (do not remove the rest). Clause 3 is correct.

Alisdair: Not sure data() is correct (in clause 2).

Conclusion: Move to open, Alisdair and Pablo volunteered to provide wording

[ originally proposed wording: ]

This wording is relative to the FDIS.

  1. Modify the class template basic_string synopsis in 21.4 [basic.string]:

    namespace std {
      template<class charT, class traits = char_traits<charT>,
        class Allocator = allocator<charT> >
      class basic_string {
      public:
        […]
        basic_string& operator=(basic_string&& str) noexcept;
        […]
        basic_string& assign(basic_string&& str) noexcept;
        […]
      };
    }
    
  2. Remove the definition of the basic_string move assignment operator from 21.4.2 [string.cons] entirely, including Table 71 — operator=(const basic_string<charT, traits, Allocator>&&). This is consistent with how we define move assignment for the containers in Clause 23:

    basic_string<charT,traits,Allocator>&
    operator=(basic_string<charT,traits,Allocator>&& str) noexcept;
    

    -22- Effects: If *this and str are not the same object, modifies *this as shown in Table 71. [ Note: A valid implementation is swap(str). — end note ]

    -23- If *this and str are the same object, the member has no effect.

    -24- Returns: *this

    Table 71 — operator=(const basic_string<charT, traits, Allocator>&&)
    Element Value
    data() points at the array whose first element was pointed at by str.data()
    size() previous value of str.size()
    capacity() a value at least as large as size()
  3. Modify the paragraphs prior to 21.4.6.3 [string::assign] p.3 as indicated (The first insertion recommends a separate paragraph number for the indicated paragraph):

    basic_string& assign(basic_string&& str) noexcept;
    

    -?- Effects: Equivalent to *this = std::move(str). The function replaces the string controlled by *this with a string of length str.size() whose elements are a copy of the string controlled by str. [ Note: A valid implementation is swap(str). — end note ]

    -3- Returns: *this

[ 2012-08-11 Joe Gottman observes: ]

One of the effects of basic_string's move-assignment operator (21.4.2 [string.cons], Table 71) is

Element Value
data() points at the array whose first element was pointed at by str.data()

If a string implementation uses the small-string optimization and the input string str is small enough to make use of it, this effect is impossible to achieve. To use the small string optimization, a string has to be implemented using something like

union
{
   char buffer[SMALL_STRING_SIZE];
   char *pdata;
};

When the string is small enough to fit inside buffer, the data() member function returns static_cast<const char *>(buffer), and since buffer is an array variable, there is no way to implement move so that the moved-to string's buffer member variable is equal to this->buffer.

Resolution proposal:

Change Table 71 to read:

Element Value
data() points at the array whose first element was pointed at by str.data() that contains the same characters in the same order as str.data() contained before operator=() was called

Proposed resolution:


2070. allocate_shared should use allocator_traits<A>::construct

Section: 20.8.2.2.6 [util.smartptr.shared.create] Status: Open Submitter: Jonathan Wakely Opened: 2011-07-11 Last modified: 2014-01-20

View all issues with Open status.

Discussion:

20.8.2.2.6 [util.smartptr.shared.create] says:

-2- Effects: Allocates memory suitable for an object of type T and constructs an object in that memory via the placement new expression ::new (pv) T(std::forward<Args>(args)...). The template allocate_shared uses a copy of a to allocate memory. If an exception is thrown, the functions have no effect.

This explicitly requires placement new rather than using allocator_traits<A>::construct(a, (T*)pv, std::forward<Args>(args)...) In most cases that would result in the same placement new expression, but would allow more control over how the object is constructed e.g. using scoped_allocator_adaptor to do uses-allocator construction, or using an allocator declared as a friend to construct objects with no public constructors.

[ 2011-08-16 Bloomington: ]

Agreed to fix in principle, but believe that make_shared and allocate_shared have now diverged enough that their descriptions should be separated. Pablo and Stefanus to provide revised wording.

Daniel's (old) proposed resolution:

This wording is relative to the FDIS.

  1. Change the following paragraphs of 20.8.2.2.6 [util.smartptr.shared.create] as indicated (The suggested removal of the last sentence of p1 is not strictly required to resolve this issue, but is still recommended, because it does not say anything new but may give the impression that it says something new):

    template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
    template<class T, class A, class... Args>
      shared_ptr<T> allocate_shared(const A& a, Args&&... args);
    

    -1- Requires: For the template make_shared, tThe expression ::new (pv) T(std::forward<Args>(args)...), where pv has type void* and points to storage suitable to hold an object of type T, shall be well formed. For the template allocate_shared, the expression allocator_traits<A>::construct(a, pt, std::forward<Args>(args)...), where pt has type T* and points to storage suitable to hold an object of type T, shall be well formed. A shall be an allocator ([allocator.requirements]). The copy constructor and destructor of A shall not throw exceptions.

    -2- Effects: Allocates memory suitable for an object of type T and constructs an object in that memory. The template make_shared constructs the object via the placement new expression ::new (pv) T(std::forward<Args>(args)...). The template allocate_shared uses a copy of a to allocate memory and constructs the object by calling allocator_traits<A>::construct(a, pt, std::forward<Args>(args)...). If an exception is thrown, the functions have no effect.

    -3- Returns: A shared_ptr instance that stores and owns the address of the newly constructed object of type T.

    -4- Postconditions: get() != 0 && use_count() == 1

    -5- Throws: bad_alloc, or, for the template make_shared, an exception thrown from the constructor of T, or, for the template allocate_shared, an exception thrown from A::allocate or from allocator_traits<A>::constructfrom the constructor of T.

    -6- Remarks: Implementations are encouraged, but not required, to perform no more than one memory allocation. [ Note: This provides efficiency equivalent to an intrusive smart pointer. — end note ]

    -7- [ Note: These functions will typically allocate more memory than sizeof(T) to allow for internal bookkeeping structures such as the reference counts. — end note ]

[2011-12-04: Jonathan and Daniel improve wording]

See also c++std-lib-31796

[2013-10-13, Ville]

This issue is related to 2089.

Proposed resolution:

This wording is relative to the FDIS.

  1. Change the following paragraphs of 20.8.2.2.6 [util.smartptr.shared.create] as indicated:

    template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
    template<class T, class A, class... Args>
      shared_ptr<T> allocate_shared(const A& a, Args&&... args);
    

    -1- Requires: The expression ::new (pv) T(std::forward<Args>(args)...), where pv has type void* and points to storage suitable to hold an object of type T, shall be well formed. A shall be an allocator (17.6.3.5 [allocator.requirements]). The copy constructor and destructor of A shall not throw exceptions.

    -2- Effects: Equivalent to

     
    return allocate_shared<T>(allocator<T>(), std::forward<Args>(args)...);
    

    Allocates memory suitable for an object of type T and constructs an object in that memory via the placement new expression ::new (pv) T(std::forward<Args>(args)...). The template allocate_shared uses a copy of a to allocate memory. If an exception is thrown, the functions have no effect.

    -?- Remarks: An implementation may meet the effects (and the implied guarantees) without creating the allocator object [Note: That is, user-provided specializations of std::allocator may not be instantiated, the expressions ::new (pv) T(std::forward<Args>(args)...) and pv->~T() may be evaluated directly — end note].

    -3- Returns: A shared_ptr instance that stores and owns the address of the newly constructed object of type T.

    -4- Postconditions: get() != 0 && use_count() == 1

    -5- Throws: bad_alloc, or an exception thrown from A::allocate or from the constructor of T.

    -6- Remarks: Implementations are encouraged, but not required, to perform no more than one memory allocation. [Note: This provides efficiency equivalent to an intrusive smart pointer. — end note]

    -7- [Note: These functions will typically allocate more memory than sizeof(T) to allow for internal bookkeeping structures such as the reference counts. — end note]

  2. Add the following set of new paragraphs immediately following the previous paragraph 7 of 20.8.2.2.6 [util.smartptr.shared.create]:

    template<class T, class A, class... Args>
      shared_ptr<T> allocate_shared(const A& a, Args&&... args);
    

    -?- Requires: The expressions allocator_traits<A>::construct(b, pt, std::forward<Args>(args)...) and allocator_traits<A>::destroy(b, pt) shall be well-formed and well-defined, where b has type A and is a copy of a and where pt has type T* and points to storage suitable to hold an object of type T. A shall meet the allocator requirements (17.6.3.5 [allocator.requirements]).

    -?- Effects: Uses an object a2 of type allocator_traits<A>::rebind_alloc<unspecified> that compares equal to a to allocate memory suitable for an object of type T. Uses a copy b of type A from a to construct an object of type T in that memory by calling allocator_traits<A>::construct(b, pt, std::forward<Args>(args)...). If an exception is thrown, the function has no effect.

    -?- Returns: A shared_ptr instance that stores and owns the address of the newly constructed object of type T. When ownership is given up, the effects are as follows: Uses a copy b2 of type A from a to destruct an object of type T by calling allocator_traits<A>::destroy(b2, pt2) where pt2 has type T* and refers to the newly constructed object. Then uses an object of type allocator_traits<A>::rebind_alloc<unspecified> that compares equal to a to deallocate the allocated memory.

    -?- Postconditions: get() != 0 && use_count() == 1

    -?- Throws: Nothing unless memory allocation or allocator_traits<A>::construct throws an exception.

    -?- Remarks: Implementations are encouraged, but not required, to perform no more than one memory allocation. [Note: Such an implementation provides efficiency equivalent to an intrusive smart pointer. — end note]

    -?- [Note: This function will typically allocate more memory than sizeof(T) to allow for internal bookkeeping structures such as the reference counts. — end note]


2072. Unclear wording about capacity of temporary buffers

Section: 20.7.11 [temporary.buffer] Status: Open Submitter: Kazutoshi Satoda Opened: 2011-08-10 Last modified: 2012-11-14

View all other issues in [temporary.buffer].

View all issues with Open status.

Discussion:

According to 20.7.11 [temporary.buffer] p1+2:

template <class T>
pair<T*, ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;

-1- Effects: Obtains a pointer to storage sufficient to store up to n adjacent T objects. It is implementation-defined whether over-aligned types are supported (3.11).

-2- Returns: A pair containing the buffer's address and capacity (in the units of sizeof(T)), or a pair of 0 values if no storage can be obtained or if n <= 0.

I read this as prohibiting to return a buffer of which capacity is less than n, because such a buffer is not sufficient to store n objects.

The corresponding description in SGI STL is clear on this point, but I think it is a bit too verbose:

(for the return value, a pair P) [...] the buffer pointed to by P.first is large enough to hold P.second objects of type T. P.second is greater than or equal to 0, and less than or equal to len.

There seems to be two different targets of the "up to n" modification: The capacity of obtained buffer, and the actual number that the caller will store into the buffer.

First I read as the latter, and got surprised seeing that libstdc++ implementation can return a smaller buffer. I started searching about get_temporary_buffer(). After reading a quote from TC++PL at stackoverflow, I realized that the former is intended.

Such misinterpretation seems common:

Proposed resolution:


2075. Progress guarantees, lock-free property, and scheduling assumptions

Section: 1.10 [intro.multithread], 29.4 [atomics.lockfree], 29.6.5 [atomics.types.operations.req] Status: Open Submitter: Torvald Riegel Opened: 2011-08-18 Last modified: 2014-01-20

View all issues with Open status.

Discussion:

According to 1.10 [intro.multithread] p2:

"Implementations should ensure that all unblocked threads eventually make progress."

29.4 [atomics.lockfree] p2 declares the lock-free property for a particular object. However, "lock-free" is never defined, and in discussions that I had with committee members it seemed as if the standard's lock-free would be different from what lock-free means in other communities (eg, research, text books on concurrent programming, etc.).

Following 29.6.5 [atomics.types.operations.req] p7 is_lock_free() returns "true if the object is lock-free". What is returned if the object is only sometimes lock-free?

Basically, I would like to see clarifications for the progress guarantees so that users know what they can expect from implementations (and what they cannot expect!), and to give implementors a clearer understanding of which user expectations they have to implement.

  1. Elaborate on the intentions of the progress guarantee in 1.10 [intro.multithread] p2. As I don't know about your intentions, it's hard to suggest a resolution.

  2. Define the lock-free property. The definition should probably include the following points:

  3. Add a note explaining that compare-exchange-weak is not necessarily lock-free (but is nonblocking)? Or is it indeed intended to be lock-free (only allowed to fail spuriously but guaranteed to not fail eventually)? Implementing the latter might be a challenge on LL-SC machines or lead to space overheads I suppose, see the cacheline sharing example above.

[2011-12-01: Hans comments]

1.10 [intro.multithread] p2 was an intentional compromise, and it was understood at the time that it was not a precise statement. The wording was introduced by N3209, which discusses some of the issues. There were additional reflector discussions.

This is somewhat separable from the question of what lock-free means, which is probably a more promising question to focus on.

[2012, Kona]

General direction: lock-free means obstruction-free. Leave the current "should" recommendation for progress. It would take a lot of effort to try to do better.

[2012, Portland: move to Open]

The current wording of 1.10 [intro.multithread] p2 doesn't really say very much. As far as we can tell the term lock-free is nowhere defined in the standard.

James: we would prefer a different way to phrase it.

Hans: the research literature includes the term abstraction-free which might be a better fit.

Detlef: does Posix define a meaning for blocking (or locking) that we could use?

Hans: things like compare-exchange-strong can wait indefinitely.

Niklas: what about spin-locks -- still making no progress.

Hans: suspect we can only give guidance, at best. The lock-free meaning from the theoretical commmunity (forard progress will be made) is probably too strong here.

Atrur: what about livelocks?

Hans: each atomic modification completes, even if the whole thing is blocked.

Moved to open.

[2013-11-06: Jason Hearne-McGuiness comments]

Related to this issue, the wording in 29.4 [atomics.lockfree] p2,

In any given program execution, the result of the lock-free query shall be consistent for all pointers of the same type.

should be made clearer, because the object-specific (non-static) nature of the is_lock_free() functions from 29.5 [atomics.types.generic] and 29.6 [atomics.types.operations] imply that for different instances of pointers of the same type the returned value could be different.

Proposed resolution:


2076. Bad CopyConstructible requirement in set constructors

Section: 23.4.6.2 [set.cons] Status: New Submitter: Jens Maurer Opened: 2011-08-20 Last modified: 2013-10-15

View all issues with New status.

Discussion:

23.4.6.2 [set.cons] paragraph 4 says:

Requires: If the iterator’s dereference operator returns an lvalue or a non-const rvalue, then Key shall be CopyConstructible.

I'm confused why a "non-const rvalue" for the return value of the iterator would require CopyConstructible; isn't that exactly the situation when you'd want to apply the move constructor?

The corresponding requirement for multimap seems better in that regard ([multimap.cons] paragraph 3):

Requires: If the iterator’s dereference operator returns an lvalue or a const rvalue pair<key_type, mapped_type>, then both key_type and mapped_type shall be CopyConstructible.

Obviously, if I have a const rvalue, I can't apply the move constructor (which will likely attempt modify its argument).

Dave Abrahams:

I think you are right. Proposed resolution: drop "non-" from 23.4.6.2 [set.cons] paragraph 3.

[2012, Kona]

The wording is in this area will be affected by Pablo's paper being adopted at this meeting. Wait for that paper to be applied before visiting this issue - deliberately leave in New status until the next meeting.

Proposed resolution from Kona 2012:

This wording is relative to the FDIS.

Change 23.4.6.2 [set.cons] p3 as follows:

template <class InputIterator>
  set(InputIterator first, InputIterator last,
    const Compare& comp = Compare(), const Allocator& = Allocator());

-3- Effects: Constructs an empty set using the specified comparison object and allocator, and inserts elements from the range [first,last).

-4- Requires: If the iterator’s dereference operator returns an lvalue or a non-const rvalue, then Key shall be CopyConstructible.

-5- Complexity: Linear in N if the range [first,last) is already sorted using comp and otherwise N logN, where N is last - first.

Proposed resolution:

This wording is relative to the N3691.

Change 23.4.6.2 [set.cons] p4 as follows:

template <class InputIterator>
  set(InputIterator first, InputIterator last,
    const Compare& comp = Compare(), const Allocator& = Allocator());

-3- Effects: Constructs an empty set using the specified comparison object and allocator, and inserts elements from the range [first,last).

-4- Requires: If the iterator’s indirection operator returns an lvalue or a non-const rvalue, then Key shall be CopyInsertible into *this.

-5- Complexity: Linear in N if the range [first,last) is already sorted using comp and otherwise N logN, where N is last - first.


2077. Further incomplete constraints for type traits

Section: 20.10.4.3 [meta.unary.prop] Status: Open Submitter: Daniel Krügler Opened: 2011-08-20 Last modified: 2012-11-14

View other active issues in [meta.unary.prop].

View all other issues in [meta.unary.prop].

View all issues with Open status.

Discussion:

The currently agreed on proposed wording for 2015 using remove_all_extents<T>::type instead of the "an array of unknown bound" terminology in the precondition should be extended to some further entries especially in Table 49, notably the is_*constructible, is_*assignable, and is_*destructible entries. To prevent ODR violations, incomplete element types of arrays must be excluded for value-initialization and destruction for example. Construction and assignment has to be honored, when we have array-to-pointer conversions or pointer conversions of incomplete pointees in effect.

[2012, Kona]

The issue is that in three type traits, we are accidentally saying that in certain circumstances the type must give a specified answer when given an incomplete type. (Specifically: an array of unknown bound of incomplete type.) The issue asserts that there's an ODR violation, since the trait returns false in that case but might return a different version when the trait is completed.

Howard argues: no, there is no risk of an ODR violation. is_constructible<A[]> must return false regardless of whether A is complete, so there's no reason to forbid an array of unknown bound of incomplete types. Same argument applies to is_assignable. General agreement with Howard's reasoning.

There may be a real issue for is_destructible. None of us are sure what is_destructible is supposed to mean for an array of unknown bound (regardless of whether its type is complete), and the standard doesn't make it clear. The middle column doesn't say what it's supposed to do for incomplete types.

In at least one implementation, is_destructible<A[]> does return true if A is complete, which would result in ODR violation unless we forbid it for incomplete types.

Move to open. We believe there is no issue for is_constructible or is_assignable, but that there is a real issue for is_destructible.

Proposed resolution:


2079. Required pow() overloads

Section: 26.8 [c.math] Status: New Submitter: Steve Clamage Opened: 2011-08-29 Last modified: 2012-11-14

View other active issues in [c.math].

View all other issues in [c.math].

View all issues with New status.

Discussion:

LWG issue 550 removed the functions:

float       pow(float, int);
double      pow(double, int);
long double pow(long double, int);

from header <cmath>. This change does not seem to be mentioned in Annex C, C.2.14.

Howard:

N3290 26.8 [c.math]/p11 says:

Moreover, there shall be additional overloads sufficient to ensure:

  1. If any argument corresponding to a double parameter has type long double, then all arguments corresponding to double parameters are effectively cast to long double.
  2. Otherwise, if any argument corresponding to a double parameter has type double or an integer type, then all arguments corresponding to double parameters are effectively cast to double.
  3. Otherwise, all arguments corresponding to double parameters are effectively cast to float.

From C99 7.12.7.4 we have:

double pow(double, double);

26.8 [c.math]/p11/b2 says that if the client calls pow(2.0f, 2), then the int for second argument causes the following effective call to be made:

pow(static_cast<double>(2.0f), static_cast<double>(2)) -> double

The first sentence of p11 implies that this is done by supplying the following additional overload:

double pow(float, int);

If the client calls pow(2.0, 2), then the same reasoning (b2 again) implies the following additional overload:

double pow(double, int);

If the client calls pow(2.0l, 2), then b1 implies the following additional overload:

long double pow(long double, int);

In all, p11 implies hundreds (perhaps thousands?) of extra overloads. All but one of which is a superset of the overloads required by C++98/03 (that one being pow(float, int) which had its return type changed from float to double).

In practice, at least some vendors implement p11 by using templated overloads as opposed to ordinary overloads.

Steve Clamage:

Thanks. I didn't see that those extra overloads were actually implied by p11, despite the first sentence. Without examples, the point is a bit subtle (at least for me).

Proposed resolution:


2088. std::terminate problem

Section: 18.8.3 [exception.terminate] Status: Open Submitter: Daniel Krügler Opened: 2011-09-25 Last modified: 2012-11-14

View all issues with Open status.

Discussion:

Andrzej Krzemienski reported the following on comp.std.c++:

In N3290, which is to become the official standard, in 18.8.3.4 [terminate], paragraph 1 reads

Remarks: Called by the implementation when exception handling must be abandoned for any of several reasons (15.5.1), in effect immediately after evaluating the throw-expression (18.8.3.1). May also be called directly by the program.

It is not clear what is "in effect". It was clear in previous drafts where paragraphs 1 and 2 read:

Called by the implementation when exception handling must be abandoned for any of several reasons (15.5.1). May also be called directly by the program.

Effects: Calls the terminate_handler function in effect immediately after evaluating the throw-expression (18.8.3.1), if called by the implementation, or calls the current terminate_handler function, if called by the program.

It was changed by N3189. The same applies to function unexpected (D. 11.4, paragraph 1).

Assuming the previous wording is still intended, the wording can be read "unless std::terminate is called by the program, we will use the handler that was in effect immediately after evaluating the throw-expression".

This assumes that there is some throw-expression connected to every situation that triggers the call to std::terminate. But this is not the case:

Which one is referred to?

In case std::nested_exception::rethrow_nested is called for an object that has captured no exception, there is no throw-expression involved directly (and may no throw be involved even indirectly).

Next, 18.8.3.1 [terminate.handler], paragraph 2 says

Required behavior: A terminate_handler shall terminate execution of the program without returning to the caller.

This seems to allow that the function may exit by throwing an exception (because word "return" implies a normal return).

One could argue that words "terminate execution of the program" are sufficient, but then why "without returning to the caller" would be mentioned. In case such handler throws, noexcept specification in function std::terminate is violated, and std::terminate would be called recursively - should std::abort not be called in case of recursive std::terminate call? On the other hand some controlled recursion could be useful, like in the following technique.

The here mentioned wording changes by N3189 in regard to 18.8.3.4 [terminate] p1 were done for a better separation of effects (Effects element) and additional normative wording explanations (Remarks element), there was no meaning change intended. Further, there was already a defect existing in the previous wording, which was not updated when further situations where defined, when std::terminate where supposed to be called by the implementation.

The part

"in effect immediately after evaluating the throw-expression"

should be removed and the quoted reference to 18.8.3.1 [terminate.handler] need to be part of the effects element where it refers to the current terminate_handler function, so should be moved just after

"Effects: Calls the current terminate_handler function."

It seems ok to allow a termination handler to exit via an exception, but the suggested idiom should better be replaced by a more simpler one based on evaluating the current exception pointer in the terminate handler, e.g.

void our_terminate (void) {
  std::exception_ptr p = std::current_exception();
  if (p) {
    ... // OK to rethrow and to determine it's nature
  } else {
    ... // Do something else
  }
}

[2011-12-09: Daniel comments]

A related issue is 2111.

[2012, Kona]

Move to Open.

There is an interaction with Core issues in this area that Jens is already supplying wording for. Review this issue again once Jens wording is available.

Alisdair to review clause 15.5 (per Jens suggestion) and recommend any changes, then integrate Jens wording into this issue.

Proposed resolution:


2089. std::allocator::construct should use uniform initialization

Section: 20.7.9.1 [allocator.members] Status: Open Submitter: David Krauss Opened: 2011-10-07 Last modified: 2014-01-20

View all other issues in [allocator.members].

View all issues with Open status.

Discussion:

When the EmplaceConstructible (23.2.1 [container.requirements.general]/13) requirement is used to initialize an object, direct-initialization occurs. Initializing an aggregate or using a std::initializer_list constructor with emplace requires naming the initialized type and moving a temporary. This is a result of std::allocator::construct using direct-initialization, not list-initialization (sometimes called "uniform initialization") syntax.

Altering std::allocator<T>::construct to use list-initialization would, among other things, give preference to std::initializer_list constructor overloads, breaking valid code in an unintuitive and unfixable way — there would be no way for emplace_back to access a constructor preempted by std::initializer_list without essentially reimplementing push_back.

std::vector<std::vector<int>> v;
v.emplace_back(3, 4); // v[0] == {4, 4, 4}, not {3, 4} as in list-initialization

The proposed compromise is to use SFINAE with std::is_constructible, which tests whether direct-initialization is well formed. If is_constructible is false, then an alternative std::allocator::construct overload is chosen which uses list-initialization. Since list-initialization always falls back on direct-initialization, the user will see diagnostic messages as if list-initialization (uniform-initialization) were always being used, because the direct-initialization overload cannot fail.

I can see two corner cases that expose gaps in this scheme. One occurs when arguments intended for std::initializer_list satisfy a constructor, such as trying to emplace-insert a value of {3, 4} in the above example. The workaround is to explicitly specify the std::initializer_list type, as in v.emplace_back(std::initializer_list<int>(3, 4)). Since this matches the semantics as if std::initializer_list were deduced, there seems to be no real problem here.

The other case is when arguments intended for aggregate initialization satisfy a constructor. Since aggregates cannot have user-defined constructors, this requires that the first nonstatic data member of the aggregate be implicitly convertible from the aggregate type, and that the initializer list have one element. The workaround is to supply an initializer for the second member. It remains impossible to in-place construct an aggregate with only one nonstatic data member by conversion from a type convertible to the aggregate's own type. This seems like an acceptably small hole.

The change is quite small because EmplaceConstructible is defined in terms of whatever allocator is specified, and there is no need to explicitly mention SFINAE in the normative text.

[2012, Kona]

Move to Open.

There appears to be a real concern with initializing aggregates, that can be performed only using brace-initialization. There is little interest in the rest of the issue, given the existence of 'emplace' methods in C++11.

Move to Open, to find an acceptable solution for intializing aggregates. There is the potential that EWG may have an interest in this area of language consistency as well.

[2013-10-13, Ville]

This issue is related to 2070.

Proposed resolution:

This wording is relative to the FDIS.

Change 20.7.9.1 [allocator.members] p12 as indicated:

template <class U, class... Args>
  void construct(U* p, Args&&... args);

12 Effects: ::new((void *)p) U(std::forward<Args>(args)...) if is_constructible<U, Args...>::value is true, else ::new((void *)p) U{std::forward<Args>(args)...}


2095. promise and packaged_task missing constructors needed for uses-allocator construction

Section: 30.6.5 [futures.promise], 30.6.9 [futures.task] Status: Deferred Submitter: Jonathan Wakely Opened: 2011-11-01 Last modified: 2013-10-15

View all other issues in [futures.promise].

View all issues with Deferred status.

Discussion:

This example is ill-formed according to C++11 because uses_allocator<promise<R>, A>::value is true, but is_constructible<promise<R>, A, promise<R>&&>::value is false. Similarly for packaged_task.

#include <future>
#include <memory>
#include <tuple>

using namespace std;

typedef packaged_task<void()> task;
typedef promise<void> prom;
allocator<task> a;

tuple<task, prom> t1{ allocator_arg, a };
tuple<task, prom> t2{ allocator_arg, a, task{}, prom{} };

[2012, Portland]

This is an allocator issue, and should be dealt with directly by LWG.

[2013-03-06]

Jonathan suggests to make the new constructors non-explicit and makes some representational improvements.

[2013-09 Chicago]

Move to deferred.

This issue has much in common with similar problems with std::function that are being addressed by the polymorphic allocators proposal currently under evaluation in LEWG. Defer further discussion on this topic until the final outcome of that paper and its proposed resolution is known.

Proposed resolution:

[This wording is relative to the FDIS.]

  1. Add to 30.6.5 [futures.promise], class template promise synopsis, as indicated:

    namespace std {
      template <class R>
      class promise {
      public:
        promise();
        template <class Allocator>
        promise(allocator_arg_t, const Allocator& a);
        template <class Allocator>
        promise(allocator_arg_t, const Allocator& a, promise&& rhs) noexcept;
        promise(promise&& rhs) noexcept;
        promise(const promise& rhs) = delete;
        ~promise();	
        […]
      };
      […]
    }
    
  2. Change 30.6.5 [futures.promise] as indicated:

    promise(promise&& rhs) noexcept;
    template <class Allocator>
    promise(allocator_arg_t, const Allocator& a, promise&& rhs) noexcept;
    

    -5- Effects: constructs a new promise object and transfers ownership of the shared state of rhs (if any) to the newly-constructed object.

    -6- Postcondition: rhs has no shared state.

    -?- [Note: a is not used — end note]

  3. Add to 30.6.9 [futures.task], class template packaged_task synopsis, as indicated:

    namespace std {
      template<class> class packaged_task; // undefined
    
      template<class R, class... ArgTypes>
      class packaged_task<R(ArgTypes...)> {
      public:
        // construction and destruction
        packaged_task() noexcept;
        template <class Allocator>
          packaged_task(allocator_arg_t, const Allocator& a) noexcept;
        template <class F>
          explicit packaged_task(F&& f);
        template <class F, class Allocator>
          explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
        ~packaged_task();
    	
        // no copy
        packaged_task(const packaged_task&) = delete;
        template<class Allocator>
          packaged_task(allocator_arg_t, const Allocator& a, const packaged_task&) = delete;
        packaged_task& operator=(const packaged_task&) = delete;
        
        // move support
        packaged_task(packaged_task&& rhs) noexcept;
        template <class Allocator>
          packaged_task(allocator_arg_t, const Allocator& a, packaged_task&& rhs) noexcept;
        packaged_task& operator=(packaged_task&& rhs) noexcept;
        void swap(packaged_task& other) noexcept;
        […]
      };
      […]
    }
    
  4. Change 30.6.9.1 [futures.task.members] as indicated:

    packaged_task() noexcept;
    template <class Allocator>
      packaged_task(allocator_arg_t, const Allocator& a) noexcept;
    

    -1- Effects: constructs a packaged_task object with no shared state and no stored task.

    -?- [Note: a is not used — end note]

    […]

    packaged_task(packaged_task&& rhs) noexcept;
    template <class Allocator>
      packaged_task(allocator_arg_t, const Allocator& a, packaged_task&& rhs) noexcept;
    

    -5- Effects: constructs a new packaged_task object and transfers ownership of rhs’s shared state to *this, leaving rhs with no shared state. Moves the stored task from rhs to *this.

    -6- Postcondition: rhs has no shared state.

    -?- [Note: a is not used — end note]


2101. Some transformation types can produce impossible types

Section: 20.10.7 [meta.trans] Status: Open Submitter: Daniel Krügler Opened: 2011-11-18 Last modified: 2013-10-15

View all issues with Open status.

Discussion:

Table 53 — "Reference modifications" says in regard to the type trait add_lvalue_reference (emphasize mine)

If T names an object or function type then the member typedef type shall name T&;

The problem with this specification is that function types with cv-qualifier or ref-qualifier, like

void() const
void() &

are also affected by the first part of the rule, but this would essentially mean, that instantiating add_lvalue_reference with such a type would attempt to form a type that is not defined in the C++ type system, namely

void(&)() const
void(&)() &

The general policy for TransformationTraits is to define always some meaningful mapping type, but this does not hold for add_lvalue_reference, add_rvalue_reference, and in addition to these two for add_pointer as well. The latter one would attempt to form the invalid types

void(*)() const
void(*)() &

A possible reason why those traits were specified in this way is that in C++03 (and that means for TR1), cv-qualifier were underspecified in the core language and several compilers just ignored them during template instantiations. This situation became fixed by adopting CWG issues 295 and 547.

While there is possibly some core language clarification needed (see reflector messages starting from c++std-core-20740), it seems also clear that the library should fix the specification. The suggested resolution follows the style of the specification of the support concepts PointeeType and ReferentType defined in N2914.

[2012-02-10, Kona]

Move to NAD.

These cv- and ref-qualified function types are abberations in the type system, and do not represent any actual entity defined by the language. The notion of cv- and ref- qualification applies only to the implicit *this reference in a member function.

However, these types can be produced by quirks of template metaprogramming, the question remains what the library should do about it. For exmaple, add_reference returns the original type if passed a reference type, or a void type. Conversely, add_pointer will refurn a pointer to the referenced type when passed a reference.

It is most likely that the 'right' answer in any case will depend on the context that the question is being asked, in terms of forming these obscure types. The best the LWG can do is allow an error to propogate back to the user, so they can provide their own meaningful answer in their context - with additional metaprogramming on their part. The consensus is that if anyone is dangerous enough with templates to get themselves into this problem, they will also have the skills to resolve the problem themselves. This is not going to trip up the non-expert developer.

Lastly, it was noted that this problem arises only because the language is inconsistent in providing us these nonesense types that do no really represent anything in the language. There may be some way Core or Evolution could give us a more consistent type system so that the LWG does not need to invent an answer at all, should this question need resolving. This is another reason to not specify anything at the LWG trait level at this time, leaving the other working groups free to produce the 'right' answer that we can then follow without changing the meaning of exisitng, well-defined programs.

[2012-02-10, post-Kona]

Move back to Open. Daniel is concerned that this is not an issue we can simply ignore, further details to follow.

[2012-10-06, Daniel comments]

This issue really should be resolved as a defect: First, the argument that "forming these obscure types" should "allow an error to propagate" is inconsistent with the exact same "obscure type" that would be formed when std::add_lvalue_reference<void> wouldn't have an extra rules for void types, which also cannot form references. The originally proposed resolution attempts to apply the same solution for the same common property of void types and function types with cv-qualifiers or ref-qualifier. These functions had the property of ReferentType during concept time (see CWG 749 bullet three for the final wording).

Core issue CWG 1417 has clarified that any attempt to form a reference of a pointer to a function type with cv-qualifiers or ref-qualifier is ill-formed. Unfortunately, many compilers don't implement this yet.

I also would like to warn about so-called "obscure" types: The problem is that these can occur as the side effect of finding a best match overload of function templates, where this type is exactly correct for one of these overloads, but causes a deep (not-sfinae-friendly) error for others where one of these traits are part of the signature.

Existing experience with void types shows, that this extra rule is not so unexpected. Further, any usage of the result types of these traits as argument types or return types of functions would make these ill-formed (and in a template context would be sfinaed away), so the expected effects are rarely unnoticed. Checking all existing explicit usages of the traits add_rvalue_reference, add_lvalue_reference, and add_pointer didn't show any example where the error would be silent: add_rvalue_reference is used to specify the return value of declval() and the instantiation of declval<void() const>() would be invalid, because of the attempt to return a function type. Similarly, add_lvalue_reference is used to specify the return type of unique_ptr<T>::operator*(). Again, any instantiation with void() const wouldn't remain unnoticed. The trait add_pointer is used to specify the trait std::decay and this is an interesting example, because it is well-formed when instantiated with void types, too, and is heavily used throughout the library specification. All use-cases would not be negatively affected by the suggested acceptance of function types with cv-qualifiers or ref-qualifier, because they involve types that are either function arguments, function parameters or types were references are formed from.

The alternative would be to add an additional extra rule that doesn't define a type member 'type' when we have a function type with cv-qualifiers or ref-qualifier. This is better than the current state but it is not superior than the proposal to specify the result as the original type, because both variants are sfinae-friendly. A further disadvantage of the "non-type" approach here would be that any usage of std::decay would require special protection against these function types, because instantiating std::decay<void() const> again would lead to a deep, sfinae-unfriendly error.

The following example demonstrates the problem: Even though the second f template is the best final match here, the first one will be instantiated. During that process std::decay<T>::type becomes instantiated as well and will raise a deep error, because as part of the implementation the trait std::add_pointer<void() const> becomes instantiated:

#include <type_traits>

template<class T>
typename std::decay<T>::type f(T&& t);

template<class T, class U>
U f(U u);

int main() {
  f<void() const>(0);
}

When the here proposed resolution would be applied this program would be well-formed and selects the expected function.

Previous resolution:

  1. Change Table 53 — "Reference modifications" in 20.10.7.2 [meta.trans.ref] as indicated:

    Table 53 — Reference modifications
    Template Comments
    template <class T>
    struct
    add_lvalue_reference;
    If T names an object type or if T names a function type that does not have
    cv-qualifiers or a ref-qualifier
    then the member typedef type
    shall name T&; otherwise, if T names a type “rvalue reference to T1” then
    the member typedef type shall name T1&; otherwise, type shall name T.
    template <class T>
    struct
    add_rvalue_reference;
    If T names an object type or if T names a function type that does not have
    cv-qualifiers or a ref-qualifier
    then the member typedef type
    shall name T&&; otherwise, type shall name T. [ Note: This rule reflects
    the semantics of reference collapsing (8.3.2 [dcl.ref]). For example, when a type T
    names a type T1&, the type add_rvalue_reference<T>::type is not an
    rvalue reference. — end note ]
  2. Change Table 56 — "Pointer modifications" in 20.10.7.5 [meta.trans.ptr] as indicated:

    Table 56 — Pointer modifications
    Template Comments
    template <class T>
    struct add_pointer;
    The member typedef type shall name the same type as
    If T names a function type that has cv-qualifiers or a ref-qualifier
    then the member typedef type shall name T; otherwise, it
    shall name the same type as
    remove_reference<T>::type*.

The following revised proposed resolution defines - in the absense of a proper core language definition - a new term referenceable type as also suggested by the resolution for LWG 2196 as an umbrella of the negation of void types and function types with cv-qualifiers or ref-qualifier. This simplifies and minimizes the requires wording changes.

[ 2013-09-26 ]

Daniel synchronizes wording with recent draft

Proposed resolution:

This wording is relative to N3691.

  1. Change Table 53 — "Reference modifications" in 20.10.7.2 [meta.trans.ref] as indicated:

    Table 53 — Reference modifications
    Template Comments
    template <class T>
    struct
    add_lvalue_reference;
    If T names an object type or function typea referenceable type
    then the member typedef type
    shall name T&; otherwise, if T names a type “rvalue reference to T1” then
    the member typedef type shall name T1&; otherwise,
    type shall name T.
    [ Note: This rule reflects the semantics of reference collapsing (8.3.2 [dcl.ref]). — end note ]
    template <class T>
    struct
    add_rvalue_reference;
    If T names an object type or function typea referenceable type
    then the member typedef type
    shall name T&&; otherwise, type shall name T. [ Note: This rule reflects
    the semantics of reference collapsing (8.3.2 [dcl.ref]). For example, when a type T
    names a type T1&, the type add_rvalue_reference<T>::type is not an
    rvalue reference. — end note ]
  2. Change Table 56 — "Pointer modifications" in 20.10.7.5 [meta.trans.ptr] as indicated:

    Table 56 — Pointer modifications
    Template Comments
    template <class T>
    struct add_pointer;
    If T names a referenceable type or a (possibly cv-qualified) void type then
    Tthe member typedef type shall name the same type as
    remove_reference<T>::type*; otherwise, type shall name T.

2104. unique_lock move-assignment should not be noexcept

Section: 30.4.2.2 [thread.lock.unique] Status: New Submitter: Anthony Williams Opened: 2011-11-27 Last modified: 2012-11-14

View all issues with New status.

Discussion:

I just noticed that the unique_lock move-assignment operator is declared noexcept. This function may call unlock() on the wrapped mutex, which may throw.

Suggested change: remove the noexcept specification from unique_lock::operator=(unique_lock&&) in 30.4.2.2 [thread.lock.unique] and 30.4.2.2.1 [thread.lock.unique.cons].

Daniel:

I think the situation is actually a bit more complex as it initially looks.

First, the effects of the move-assignment operator are (emphasize mine):

Effects: If owns calls pm->unlock().

Now according to the BasicLockable requirements:

m.unlock()

3 Requires: The current execution agent shall hold a lock on m.

4 Effects: Releases a lock on m held by the current execution agent.

Throws: Nothing.

This shows that unlock itself is a function with narrow contract and for this reasons no unlock function of a mutex or lock itself does have a noexcept specifier according to our mental model.

Now the move-assignment operator attempts to satisfy these requirement of the function and calls it only when it assumes that the conditions are ok, so from the view-point of the caller of the move-assignment operator it looks as if the move-assignment operator would in total a function with a wide contract.

The problem with this analysis so far is, that it depends on the assumed correctness of the state "owns".

Looking at the construction or state-changing functions, there do exist several ones that depend on caller-code satisfying the requirements and there is one guy, who looks most suspicious:

unique_lock(mutex_type& m, adopt_lock_t);

11 Requires: The calling thread own the mutex.
[…]
13 Postconditions: pm == &m and owns == true.

because this function does not even call lock() (which may, but is not required to throw an exception if the calling thread does already own the mutex). So we have in fact still a move-assignment operator that might throw an exception, if the mutex was either constructed or used (call of lock) incorrectly.

The correct fix seems to me to also add a "Throws: Nothing" element to the move-assignment operator, because using it correctly shall now throw an exception.

Proposed resolution:

This wording is relative to the FDIS.

  1. Change 30.4.2.2 [thread.lock.unique], class template unique_lock synopsis as indicated:

    namespace std {
      template <class Mutex>
      class unique_lock {
      public:
        typedef Mutex mutex_type;
        […]
        unique_lock(unique_lock&& u) noexcept;
        unique_lock& operator=(unique_lock&& u) noexcept;
        […]
      };
    }
    
  2. Change 30.4.2.2.1 [thread.lock.unique.cons] around p22 as indicated:

    unique_lock& operator=(unique_lock&& u) noexcept;
    

    -22- Effects: If owns calls pm->unlock().

    -23- Postconditions: pm == u_p.pm and owns == u_p.owns (where u_p is the state of u just prior to this construction), u.pm == 0 and u.owns == false.

    -24- [Note: With a recursive mutex it is possible for both *this and u to own the same mutex before the assignment. In this case, *this will own the mutex after the assignment and u will not. — end note]

    -??- Throws: Nothing.


2106. move_iterator wrapping iterators returning prvalues

Section: 24.5.3 [move.iterators] Status: Open Submitter: Dave Abrahams Opened: 2011-11-30 Last modified: 2013-10-15

View all other issues in [move.iterators].

View all issues with Open status.

Discussion:

Shouldn't move_iterator be specialized so that if the iterator it wraps returns a prvalue when dereferenced, the move_iterator also returns by value? Otherwise, it creates a dangling reference.

Howard: I believe just changing move_iterator<I>::reference would do. A direction might be testing on is_reference<iterator_traits<I>::reference>, or is_reference<decltype(*declval<I>())>.

Daniel: I would prefer to use a consistent style among the iterator adaptors, so I suggest to keep with the iterator_traits typedefs if possible.

using reference = typename conditional<
  is_reference<typename iterator_traits<Iterator>::reference>::value,
  value_type&&,
  value_type
>::type;

We might also want to ensure that if Iterator's reference type is a reference, the referent is equal to value_type (after removal of cv-qualifiers). In general we have no such guarantee.

Marc: In the default case where we don't return value_type&&, should we use value_type or should we keep the reference type of the wrapped iterator?

Daniel: This suggestion looks appealing at first, but the problem here is that using this typedef can make it impossible for move_iterator to satisfy its contract, which means returning an rvalue of the value type (Currently it says rvalue-reference, but this must be fixed as of this issue anyway). I think that user-code can reasonably expect that when it has constructed an object m of move_iterator<It>, where It is a valid mutable iterator type, the expression

It::value_type&& rv = *m;

is well-formed.

Let's set R equal to iterator_traits<Iterator>::reference in the following. We can discuss the following situations:

  1. R is a reference type: We can only return the corresponding xvalue of R, if value_type is reference-related to the referent type, else this is presumably no forward iterator and we cannot say much about it, except that it must be convertible to value_type, so it better should return a prvalue.
  2. R is not a reference type: In this case we can rely on a conversion to value_type again, but not much more. Assume we would return R directly, this might turn out to have a conversion to an lvalue-reference type of the value type (for example). If that is the case, this would indirectly violate the contract of move_iterator.

In regard to the first scenario I suggest that implementations are simply required to check that V2 = remove_cv<remove_reference<R>::type>::type is equal to the value type V1 as a criterion to return this reference as an xvalue, in all other cases it should return the value type directly as prvalue.

The additional advantage of this strategy is, that we always ensure that reference has the correct cv-qualification, if R is a real reference.

It is possible to improve this a bit by indeed supporting reference-related types, this would require to test is_same<V1, V2>::value || is_base_of<V1, V2>::value instead. I'm unsure whether (a) this additional effort is worth it and (b) a strict reading of the forward iterator requirements seems not to allow to return a reference-related type (Whether this is a defect or not is another question).

[2011-12-05: Marc Glisse comments and splits into two resolution alternatives]

I guess I am looking at the speed of:

value_type x;
x = *m;

(copy construction would likely trigger copy elision and thus be neutral) instead of the validity of:

value_type&& x = *m;

In this sense, Daniels earlier proposition that ignored value_type and just did switch_lvalue_ref_to_rvalue_ref<reference> was easier to understand (and it didn't require thinking about reference related types).

The currently proposed resolution has been split into two alternatives.

[2012, Kona]

Move to Review.

Alisdair: This only applies to input iterators, so keep that in mind when thinking about this.

STL: I see what B is doing, but not A.

Howard: I agree.

Alisdair: Should we use add_rvalue_reference?

STL: No, we do not want reference collapsing.

STL: Re A, messing with the CV qualification scares me.

Alisdair: Agree. That would break my intent.

STL: Actually I don't think it's actually wrong, but I still don't see what it's doing.

Alisdair: A is picking the value type, B is picking the proxy type.

Howard: I like returning the proxy type.

STL: Returning a reference (B) seems right, because the requirements say "reference". I suspect that B works correctly if you have a move iterator wrapping a move iterator wrapping a thing. I think that A would mess up the type in the middle.

Considerable discussion about which version is correct, checking various examples.

STL: Still think B is right. Still don't understand A. In A we are losing the proxyness.

Howard: Agree 100%. We don't want to lose the proxy. If it's const, so be it.

STL: B is also understandable by mortals.

Howard: Remove to review, keep A but move it out of the proposed resolution area (but keep it for rational).

Alisdair: Adding an explanatory note might be a good idea, if someone wants to write one.

Walter: Concerned about losing the word "reference" in p.1.

Howard: move_iterator will return an xvalue or a prvalue, both of which are rvalues.

[Proposed resolution A, rejected in preference to the currently proposed resolution (B)

  1. Change 24.5.3 [move.iterators] p1 as indicated:

    Class template move_iterator is an iterator adaptor with the same behavior as the underlying iterator except that its dereference operator implicitly converts the value returned by the underlying iterator’s dereference operator to an rvalue referenceof the value type. Some generic algorithms can be called with move iterators to replace copying with moving.

  2. Change 24.5.3.1 [move.iterator], class template move_iterator synopsis, as indicated:

    namespace std {
      template <class Iterator>
      class move_iterator {
      public:
        typedef Iterator iterator_type;
        typedef typename iterator_traits<Iterator>::difference_type difference_type;
        typedef Iterator pointer;
        typedef typename iterator_traits<Iterator>::value_type value_type;
        typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
        typedef value_type&&see below reference;
        […]
      };
    }
    
  3. Immediately following the class template move_iterator synopsis in 24.5.3.1 [move.iterator] insert a new paragraph as indicated:

    -?- Let R be iterator_traits<Iterator>::reference and let V be iterator_traits<Iterator>::value_type. If is_reference<R>::value is true and if remove_cv<remove_reference<R>::type>::type is the same type as V, the template instantiation move_iterator<Iterator> shall define the nested type named reference as a synonym for remove_reference<R>::type&&, otherwise as a synonym for V.

]

[2012, Portland: Move to Tentatively Ready]

AJM wonders if the implied trait might be useful elsewhere, and worth adding to type traits as a transformation type trait.

Suspicion that the Range SG might find such a trait useful, but wait until there is clear additional use of such a trait before standardizing.

Minor wording tweak to use add_rvalue_reference rather than manually adding the &&, then move to Tentatively Ready.

[2013-01-09 Howard Hinnat comments]

I believe the P/R for LWG 2106 is incorrect (item 3). The way it currently reads, move_iterator<I>::reference is always an lvalue reference. I.e. if R is an lvalue reference type, then reference becomes add_rvalue_reference<R>::type which is just R. And if R is not a reference type, then reference becomes R (which is also just R ;-)).

I believe the correct wording is what was there previously:

-?- Let R be iterator_traits<Iterator>::reference. If is_reference<R>::value is true, the template instantiation move_iterator<Iterator> shall define the nested type named reference as a synonym for remove_reference<R>::type&&, otherwise as a synonym for R.

Additionally Marc Glisse points out that move_iterator<I>::operator*() should return static_cast<reference>(*current), not std::move(*current).

Previous resolution:

This wording is relative to the FDIS.

  1. Change 24.5.3 [move.iterators] p1 as indicated:

    Class template move_iterator is an iterator adaptor with the same behavior as the underlying iterator except that its dereference operator implicitly converts the value returned by the underlying iterator’s dereference operator to an rvalue reference. Some generic algorithms can be called with move iterators to replace copying with moving.

  2. Change 24.5.3.1 [move.iterator], class template move_iterator synopsis, as indicated:

    namespace std {
      template <class Iterator>
      class move_iterator {
      public:
        typedef Iterator iterator_type;
        typedef typename iterator_traits<Iterator>::difference_type difference_type;
        typedef Iterator pointer;
        typedef typename iterator_traits<Iterator>::value_type value_type;
        typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
        typedef value_type&&see below reference;
        […]
      };
    }
    
  3. Immediately following the class template move_iterator synopsis in 24.5.3.1 [move.iterator] insert a new paragraph as indicated:

    -?- Let R be iterator_traits<Iterator>::reference. If is_reference<R>::value is true, the template instantiation move_iterator<Iterator> shall define the nested type named reference as a synonym for add_rvalue_reference<R>::type, otherwise as a synonym for R.

Proposed resolution:

This wording is relative to N3485.

  1. Change 24.5.3 [move.iterators] p1 as indicated:

    Class template move_iterator is an iterator adaptor with the same behavior as the underlying iterator except that its indirection operator implicitly converts the value returned by the underlying iterator’s indirection operator to an rvalue reference. Some generic algorithms can be called with move iterators to replace copying with moving.

  2. Change 24.5.3.1 [move.iterator], class template move_iterator synopsis, as indicated:

    namespace std {
      template <class Iterator>
      class move_iterator {
      public:
        typedef Iterator iterator_type;
        typedef typename iterator_traits<Iterator>::difference_type difference_type;
        typedef Iterator pointer;
        typedef typename iterator_traits<Iterator>::value_type value_type;
        typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
        typedef value_type&&see below reference;
        […]
      };
    }
    
  3. Immediately following the class template move_iterator synopsis in 24.5.3.1 [move.iterator] insert a new paragraph as indicated:

    -?- Let R be iterator_traits<Iterator>::reference. If is_reference<R>::value is true, the template instantiation move_iterator<Iterator> shall define the nested type named reference as a synonym for remove_reference<R>::type&&, otherwise as a synonym for R.

  4. Edit 24.5.3.3.4 [move.iter.op.star] p1 as indicated:

    reference operator*() const;
    

    -1- Returns: std::movestatic_cast<reference>(*current).


2108. No way to identify allocator types that always compare equal

Section: 17.6.3.5 [allocator.requirements] Status: Open Submitter: Jonathan Wakely Opened: 2011-12-01 Last modified: 2012-11-14

View other active issues in [allocator.requirements].

View all other issues in [allocator.requirements].

View all issues with Open status.

Discussion:

Whether two allocator objects compare equal affects the complexity of container copy and move assignments and also the possibility of an exception being thrown by container move assignments. The latter point means container move assignment cannot be noexcept when propagate_on_container_move_assignment (POCMA) is false for the allocator because there is no way to detect at compile-time if two allocators will compare equal. LWG 2013 means this affects all containers using std::allocator, but even if that is resolved, this affects all stateless allocators which do not explicitly define POCMA to true_type.

One solution would be to add an "always_compare_equal" trait to allocator_traits, but that would be duplicating information that is already defined by the type's equality operator if that operator always returns true. Requiring users to write operator== that simply returns true and also explicitly override a trait to repeat the same information would be unfortunate and risk user errors that allow the trait and actual operator== to disagree.

Dave Abrahams suggested a better solution in message c++std-lib-31532, namely to allow operator== to return true_type, which is convertible to bool but also detectable at compile-time. Adopting this as the recommended way to identify allocator types that always compare equal only requires a slight relaxation of the allocator requirements so that operator== is not required to return bool exactly.

The allocator requirements do not make it clear that it is well-defined to compare non-const values, that should be corrected too.

In message c++std-lib-31615 Pablo Halpern suggested an always_compare_equal trait that could still be defined, but with a sensible default value rather than requiring users to override it, and using that to set sensible values for other allocator traits:

Do we still need always_compare_equal if we can have an operator== that returns true_type? What would its default value be? is_empty<A> || is_convertible<decltype(a == a), true_type>::value, perhaps? One benefit I see to such a definition is that stateless C++03 allocators that don't use the true_type idiom will still benefit from the new trait.

[…]

One point that I want to ensure doesn't get lost is that if we adopt some sort of always_compare_equal-like trait, then propagate_on_container_swap and propagate_on_container_move_assignment should default to always_compare_equal. Doing this will eliminate unnecessary requirements on the container element type, as per [LWG 2103].

Optionally, operator== for std::allocator could be made to return true_type, however if LWG 2103 is adopted that is less important.

Alberto Ganesh Barbati: Suggest either always_compare_equal, all_objects_(are_)equivalent, or all_objects_compare_equal.

Proposed resolution:

This wording is relative to the FDIS.

  1. Change Table 27 — "Descriptive variable definitions" in 17.6.3.5 [allocator.requirements]:

    Table 27 — Descriptive variable definitions
    Variable Definition
    a3, a4 an rvalue ofvalues of (possibly const) type X
    b a value of (possibly const) type Y
  2. Change Table 28 — "Allocator requirements" in 17.6.3.5 [allocator.requirements]:

    Table 28 — Allocator requirements
    Expression Return type Assertion/note pre-/post-condition Default
    a1 == a2a3 == a4 convertible to bool returns true only if storage
    allocated from each can be
    deallocated via the other.
    operator== shall be reflexive,
    symmetric, and transitive, and
    shall not exit via an exception.
    a1 != a2a3 != a4 convertible to bool same as !(a1 == a2)!(a3 == a4)
    a3 == b convertible to bool same as a3 ==
    Y::rebind<T>::other(b)
    a3 != b convertible to bool same as !(a3 == b)
    […]
    a.select_on_-
    container_copy_-
    construction()
    X Typically returns either a or
    X()
    return a;
    X::always_compares_equal Identical to or derived
    from true_type or
    false_type
    true_type if the expression x1 == x2 is
    guaranteed to be true for any two (possibly
    const) values x1, x2 of type X, when
    implicitly converted to bool. See Note B, below.
    true_type, if is_empty<X>::value is true or if
    decltype(declval<const X&>() == declval<const X&>())
    is convertible to true_type, otherwise false_type.
    […]

    Note A: […]

    Note B: If X::always_compares_equal::value or XX::always_compares_equal::value evaluate to true and an expression equivalent to x1 == x2 or x1 != x2 for any two values x1, x2 of type X evaluates to false or true, respectively, the behaviour is undefined.

  3. Change class template allocator_traits synopsis, 20.7.8 [allocator.traits] as indicated:

    namespace std {
      template <class Alloc> struct allocator_traits {
        typedef Alloc allocator_type;
        […]
        typedef see below always_compares_equal;
        typedef see below propagate_on_container_copy_assignment;
        […]
      };
    }
    
  4. Insert the following between 20.7.8.1 [allocator.traits.types] p6 and p7 as indicated:

    typedef see below always_compares_equal;
    

    -?- Type: Alloc::always_compares_equal if such a type exists; otherwise, true_type if is_empty<Alloc>::value is true or if decltype(declval<const Alloc&>() == declval<const Alloc&>()) is convertible to true_type; otherwise, false_type .

    typedef see below propagate_on_container_copy_assignment;
    

    -7- Type: Alloc::propagate_on_container_copy_assignment if such a type exits, otherwise false_type.

  5. Change class template allocator synopsis, 20.7.9 [default.allocator] as indicated:

    namespace std {
      template <class T> class allocator;
    
      // specialize for void:
      template <> class allocator<void> {
      public:
        typedef void* pointer;
        typedef const void* const_pointer;
        // reference-to-void members are impossible.
        typedef void value_type;
        template <class U> struct rebind { typedef allocator<U> other; };
      };
    
      template <class T> class allocator {
      public:
        typedef size_t size_type;
        typedef ptrdiff_t difference_type;
        typedef T* pointer;
        typedef const T* const_pointer;
        typedef T& reference;
        typedef const T& const_reference;
        typedef T value_type;
        template <class U> struct rebind { typedef allocator<U> other; };
        typedef true_type always_compares_equal;
    
        […]
      };
    }
    

2111. Which unexpected/terminate handler is called from the exception handling runtime?

Section: 18.8.3.4 [terminate], D.11.4 [unexpected] Status: Open Submitter: Howard Hinnant Opened: 2011-12-06 Last modified: 2012-11-14

View all other issues in [terminate].

View all issues with Open status.

Discussion:

Prior to N3242, modified by N3189, we said this about unexpected():

Effects: Calls the unexpected_handler function in effect immediately after evaluating the throw-expression (D.13.1), if called by the implementation, or calls the current unexpected_handler, if called by the program.

and this about terminate():

Effects: Calls the terminate_handler function in effect immediately after evaluating the throw-expression (18.8.3.1), if called by the implementation, or calls the current terminate_handler function, if called by the program.

But now in both places we say:

Calls the current unexpected_handler function.

and:

Calls the current terminate function.

The difference is that in C++98/03 if a destructor reset a handler during stack unwinding, that new handler was not called if the unwinding later led to unexpected() or terminate() being called. But these new words say that this new handler is called. This is an ABI-breaking change in the way exceptions are handled. Was this change intentional?

N3189 was mainly about introducing exception safety and getters for the handlers. I don't recall the issue of which handler gets called being part of the discussion.

I propose that we revert to the C++98/03 behavior in this regard, lest ABI's such as the Itanium ABI are invalidated. A mechanical way to do this is to revert bullets 9 and 12 of N3189.

[2011-12-09: Daniel comments]

There was no such semantic change intended. It was an unfortunate side effect when trying to better separate different responsibilities in the previous wording.

A related issue is 2088.

[2012-01-30: Howard comments]

The C++98/03 wording is somewhat ambiguous:

Calls the terminate_handler function in effect immediately after evaluating the throw-expression...

There are potentially two throw-expressions being referred to here, and it is not clear if this sentence is referring to just the first or both:

  1. throw assignment-expression;
  2. throw;

There is ample evidence in current implementations that it is understood that only 1. was meant. But clearly both 1 and 2 could have been meant. We need a clarification. Does an execution of a rethrow (throw;) update which handlers can potentially be called?

  1. throw; // update handlers to get_xxx()?

My opinion: Go with existing practice, and clarify what that practice is, if surveys find that everyone does the same thing. Gcc 4.2 and Apple do 1. only, and do not reset the handlers to the current handlers on throw;.

If current practice is not unanimously one way or the other, I have no strong opinion. I have not found a motivating use case for the use of any particular handler. Most applications set the handlers once at the beginning of the program and then do not change them, and so will not be impacted by whatever decision is made here.

Proposed resolution:


2112. User-defined classes that cannot be derived from

Section: 17.6.5 [conforming], 20.7.8 [allocator.traits], 20.13.1 [allocator.adaptor.syn] Status: Open Submitter: Daniel Krügler Opened: 2011-11-30 Last modified: 2012-11-14

View all other issues in [conforming].

View all issues with Open status.

Discussion:

It is a very established technique for implementations to derive internally from user-defined class types that are used to customize some library component, e.g. deleters and allocators are typical candidates. The advantage of this approach is to possibly take advantage of the empty-base-class optimization (EBCO).

Whether or whether not libraries did take advantage of such a detail didn't much matter in C++03. Even though there did exist a portable idiom to prevent that a class type could be derived from, this idiom has never reached great popularity: The technique required to introduce a virtual base class and it did not really prevent the derivation, but only any construction of such a type. Further, such types are not empty as defined by the std::is_empty trait, so could easily be detected by implementations from TR1 on.

With the new C++11 feature of final classes and final member functions it is now very easy to define an empty, but not derivable from class type. From the point of the user it is quite natural to use this feature for types that he or she did not foresee to be derivable from.

On the other hand, most library implementations (including third-party libraries) often take advantage of EBCO applied to user-defined types used to instantiate library templates internally. As the time of submitting this issue the following program failed to compile on all tested library implementations:

#include <memory>

struct Noop final {
 template<class Ptr>
 void operator()(Ptr) const {}
};

std::unique_ptr<int, Noop> up;

In addition, many std::tuple implementations with empty, final classes as element types failed as well, due to a popular inheritance-based implementation technique. EBCO has also a long tradition to be used in library containers to efficiently store potentially stateless, empty allocators.

It seems that both user and library did the best they could: None of the affected types did impose explicit requirements on the corresponding user-defined types to be derivable from (This capability was not part of the required operations), and libraries did apply EBCO whereever possible to the convenience of the customer.

Nonetheless given the existence of non-derivable-from class types in C++11, libraries have to cope with failing derivations. How should that problem be solved?

It would certainly be possible to add weazel wording to the allocator requirements similar to what we had in C++03, but restricted to derivation-from requirements. I consider this as the bad solution, because it would add new requirements that never had existed before in this explicit form onto types like allocators.

Existing libraries presumably will need internal traits like __is_final or __is_derivable to make EBCO possible in the current form but excluding non-derivable class types. As of this writing this seems to happen already. Problem is that without a std::is_derivable trait, third-party libraries have no portable means to do the same thing as standard library implementations. This should be a good reason to make such a trait public available soon, but seems not essential to have now. Further, this issue should also be considered as a chance to recognice that EBCO has always been a very special corner case (There exist parallels to the previously existing odd core language rule that did make the interplay between std::auto_ptr and std::auto_ptr_ref possible) and that it would be better to provide explicit means for space-efficient storage, not necessarily restricted to inheritance relations, e.g. by marking data members with a special attribute.

At least two descriptions in the current standard should be fixed now for better clarification:

  1. As mentioned by Ganesh, 20.7.8 [allocator.traits] p1 currently contains a (non-normative) note "Thus, it is always possible to create a derived class from an allocator." which should be removed.

  2. As pointed out by Howard, the specification of scoped_allocator_adaptor as of 20.13.1 [allocator.adaptor.syn] already requires derivation from OuterAlloc, but only implies indirectly the same for the inner allocators due to the exposition-only description of member inner. This indirect implication should be normatively required for all participating allocators.

[2012, Kona]

What we really need is a type trait to indicate if a type can be derived from. Howard reports Clang and libc++ have had success with this approach.

Howard to provide wording, and AJM to alert Core that we may be wanting to add a new trait that requires compiler support.

Proposed resolution:


2114. Incorrect "contextually convertible to bool" requirements

Section: 17.6.3.3 [nullablepointer.requirements], 24.2.3 [input.iterators], 24.2.7 [random.access.iterators], 25.1 [algorithms.general], 25.4 [alg.sorting], 30.2.1 [thread.req.paramname] Status: Open Submitter: Daniel Krügler Opened: 2011-12-09 Last modified: 2012-11-14

View all issues with Open status.

Discussion:

As of 17.6.3.1 [utility.arg.requirements] Table 17/18, the return types of the expressions

a == b

or

a < b

for types satisfying the EqualityComparable or LessThanComparable types, respectively, are required to be "convertible to bool" which corresponds to a copy-initialization context. But several newer parts of the library that refer to such contexts have lowered the requirements taking advantage of the new terminology of "contextually convertible to bool" instead, which corresponds to a direct-initialization context (In addition to "normal" direct-initialization constructions, operands of logical operations as well as if or switch conditions also belong to this special context).

One example for these new requirements are input iterators which satisfy EqualityComparable but also specify that the expression

a != b

shall be just "contextually convertible to bool". The same discrepancy exists for requirement set NullablePointer in regard to several equality-related expressions.

For random access iterators we have

a < b contextually convertible to bool

as well as for all derived comparison functions, so strictly speaking we could have a random access iterator that does not satisfy the LessThanComparable requirements, which looks like an artifact to me.

Even if we keep with the existing requirements based on LessThanComparable or EqualityComparable we still would have the problem that some current specifications are actually based on the assumption of implicit convertibility instead of "explicit convertibility", e.g. 20.8.1.5 [unique.ptr.special] p3:

template <class T1, class D1, class T2, class D2>
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);

-3- Returns: x.get() != y.get().

Similar examples exist in 20.8.1.2.2 [unique.ptr.single.dtor] p2, 20.8.1.2.3 [unique.ptr.single.asgn] p9, 20.8.1.2.4 [unique.ptr.single.observers] p1+3+8, etc.

In all these places the expressions involving comparison functions (but not those of the conversion of a NullablePointer to bool!) assume to be "convertible to bool". I think this is a very natural assumption and all delegations of the comparison functions of some type X to some other API type Y in third-party code does so assuming that copy-initialization semantics will just work.

The actual reason for using the newer terminology can be rooted back to LWG 556. My hypotheses is that the resolution of that issue also needs a slight correction. Why so?

The reason for opening that issue were worries based on the previous "convertible to bool" wording. An expressions like "!pred(a, b)" might not be well-formed in those situations, because operator! might not be accessible or might have an unusual semantics (and similarly for other logical operations). This can indeed happen with unusual proxy return types, so the idea was that the evaluation of Predicate, BinaryPredicate (25.1 [algorithms.general] p8+9), and Compare (25.4 [alg.sorting] p2) should be defined based on contextual conversion to bool. Unfortunately this alone is not sufficient: In addition, I think, we also want the predicates to be (implicitly) convertible to bool! Without this wording, several conditions are plain wrong, e.g. 25.2.5 [alg.find] p2, which talks about "pred(*i) != false" (find_if) and "pred(*i) == false" (find_if_not). These expressions are not within a boolean context!

While we could simply fix all these places by proper wording to be considered in a "contextual conversion to bool", I think that this is not the correct solution: Many third-party libraries already refer to the previous C++03 Predicate definition — it actually predates C++98 and is as old as the SGI specification. It seems to be a high price to pay to switch to direct initialization here instead of fixing a completely different specification problem.

A final observation is that we have another definition for a Predicate in 30.2.1 [thread.req.paramname] p2:

If a parameter is Predicate, operator() applied to the actual template argument shall return a value that is convertible to bool.

The problem here is not that we have two different definitions of Predicate in the standard — this is confusing, but this fact alone is not a defect. The first (minor) problem is that this definition does not properly apply to function objects that are function pointers, because operator() is not defined in a strict sense. But the actually worse second problem is that this wording has the very same problem that has originally lead to LWG 556! We only need to look at 30.5.1 [thread.condition.condvar] p15 to recognice this:

while (!pred())
  wait(lock);

The negation expression here looks very familiar to the example provided in LWG 556 and is sensitive to the same "unusual proxy" problem. Changing the 30.2.1 [thread.req.paramname] wording to a corresponding "contextual conversion to bool" wouldn't work either, because existing specifications rely on "convertible to bool", e.g. 30.5.1 [thread.condition.condvar] p32+33+42 or 30.5.2 [thread.condition.condvarany] p25+26+32+33.

To summarize: I believe that LWG 556 was not completely resolved. A pessimistic interpretation is, that even with the current wording based on "contextually convertible to bool" the actual problem of that issue has not been fixed. What actually needs to be required here is some normative wording that basically expresses something along the lines of:

The semantics of any contextual conversion to bool shall be equivalent to the semantics of any implicit conversion to bool.

This is still not complete without having concepts, but it seems to be a better approximation. Another way of solving this issue would be to define a minimum requirements table with equivalent semantics. The proposed wording is a bit simpler but attempts to express the same thing.

[2012, Kona]

Agree with Daniel that we potentially broke some C++03 user code, accept the changes striking "contextually" from tables. Stefan to provide revised wording for section 25, and figure out changes to section 30.

Move to open, and then to Review when updated wording from Stefan is available.

[2012-10-12, STL comments]

  1. The current proposed resolution still isn't completely satisfying. It would certainly be possible for the Standard to require these various expressions to be implicitly and contextually convertible to bool, but that would have a subtle consequence (which, I will argue, is undesirable - regardless of the fact that it dates all the way back to C++98/03). It would allow users to provide really wacky types to the Standard Library, with one of two effects:

    1. Standard Library implementations would have to go to great lengths to respect such wacky types, essentially using static_cast<bool> when invoking any predicates or comparators.

    2. Otherwise, such wacky types would be de facto nonportable, because they would make Standard Library implementations explode.

    Effect B is the status quo we're living with today. What Standard Library implementations want to do with pred(args) goes beyond "if (pred(args))" (C++03), contextually converting pred(args) to bool (C++11), or implicitly and contextually converting pred(args) to bool (the current proposed resolution). Implementations want to say things like:

    if (pred(args))
    if (!pred(args))
    if (cond && pred(args))
    if (cond && !pred(args))
    

    These are real examples taken from Dinkumware's implementation. There are others that would be realistic ("pred(args) && cond", "cond || pred(args)", etc.)

    Although negation was mentioned in this issue's Discussion section, and in LWG 556's, the current proposed resolution doesn't fix this problem. Requiring pred(args) to be implicitly and contextually convertible to bool doesn't prevent operator!() from being overloaded and returning std::string (as a wacky example). More ominously, it doesn't prevent operator&&() and operator||() from being overloaded and destroying short-circuiting.

  2. I would like LWG input before working on Standardese for a new proposed resolution. Here's an outline of what I'd like to do:

    1. Introduce a new "concept" in 17.6.3 [utility.requirements], which I would call BooleanTestable in the absence of better ideas.

    2. Centralize things and reduce verbosity by having everything simply refer to BooleanTestable when necessary. I believe that the tables could say "Return type: BooleanTestable", while Predicate/BinaryPredicate/Compare would need the incantation "shall satisfy the requirements of BooleanTestable".

    3. Resolve the tug-of-war between users (who occasionally want to do weird things) and implementers (who don't want to have to contort their code) by requiring that:

      1. Given a BooleanTestable x, x is both implicitly and contextually convertible to bool.

      2. Given a BooleanTestable x, !x is BooleanTestable. (This is intentionally "recursive".)

      3. Given a BooleanTestable x, bool t = x, t2(x), f = !x; has the postcondition t == t2 && t != f.

      4. Given a BooleanTestable x and a BooleanTestable y of possibly different types, "x && y" and "x || y" invoke the built-in operator&&() and operator||(), triggering short-circuiting.

      5. bool is BooleanTestable.

    I believe that this simultaneously gives users great latitude to use types other than bool, while allowing implementers to write reasonable code in order to get their jobs done. (If I'm forgetting anything that implementers would want to say, please let me know.)

  3. About requirement (I): As Daniel patiently explained to me, we need to talk about both implicit conversions and contextual conversions, because it's possible for a devious type to have both "explicit operator bool()" and "operator int()", which might behave differently (or be deleted, etc.).

  4. About requirement (IV): This is kind of tricky. What we'd like to say is, "BooleanTestable can't ever trigger an overloaded logical operator". However, given a perfectly reasonable type Nice - perhaps even bool itself! - other code (perhaps a third-party library) could overload operator&&(Nice, Evil). Therefore, I believe that the requirement should be "no first use" - the Standard Library will ask for various BooleanTestable types from users (for example, the result of "first != last" and the result of "pred(args)"), and as long as they don't trigger overloaded logical operators with each other, everything is awesome.

  5. About requirement (V): This is possibly redundant, but it's trivial to specify, makes it easier for users to understand what they need to do ("oh, I can always achieve this with bool"), and provides a "base case" for requirement (IV) that may or may not be necessary. Since bool is BooleanTestable, overloading operator&&(bool, Other) (etc.) clearly makes the Other type non-BooleanTestable.

Proposed resolution:

This wording is relative to the FDIS.

  1. Change Table 25 — "NullablePointer requirements" in 17.6.3.3 [nullablepointer.requirements] as indicated:

    Table 25 — NullablePointer requirements
    Expression Return type Operational semantics
    […]
    a != b contextually convertible to bool !(a == b)
    a == np
    np == a
    contextually convertible to bool a == P()
    a != np
    np != a
    contextually convertible to bool !(a == np)
  2. Change Table 107 — "Input iterator requirements" in 24.2.3 [input.iterators] as indicated:

    Table 107 — Input iterator requirements (in addition to Iterator)
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    a != b contextually convertible to bool !(a == b) pre: (a, b) is in the domain of ==.
    […]
  3. Change Table 111 — "Random access iterator requirements" in 24.2.7 [random.access.iterators] as indicated:

    Table 111 — Random access iterator requirements (in addition to bidirectional iterator)
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    […]
    a < b contextually convertible to bool b - a > 0 < is a total ordering relation
    a > b contextually convertible to bool b < a > is a total ordering relation opposite to <.
    a >= b contextually convertible to bool !(a < b)
    a <= b contextually convertible to bool !(a > b)
  4. Change 25.1 [algorithms.general] p8+9 as indicated:

    -8- The Predicate parameter is used whenever an algorithm expects a function object (20.9 [function.objects]) that, when applied to the result of dereferencing the corresponding iterator, returns a value testable as true. In other words, if an algorithm takes Predicate pred as its argument and first as its iterator argument, it should work correctly in the construct pred(*first) implicitly or contextually converted to bool (Clause 4 [conv]). The function object pred shall not apply any non-constant function through the dereferenced iterator.

    -9- The BinaryPredicate parameter is used whenever an algorithm expects a function object that when applied to the result of dereferencing two corresponding iterators or to dereferencing an iterator and type T when T is part of the signature returns a value testable as true. In other words, if an algorithm takes BinaryPredicate binary_pred as its argument and first1 and first2 as its iterator arguments, it should work correctly in the construct binary_pred(*first1, *first2) implicitly or contextually converted to bool (Clause 4 [conv]). BinaryPredicate always takes the first iterator's value_type as its first argument, that is, in those cases when T value is part of the signature, it should work correctly in the construct binary_pred(*first1, value) implicitly or contextually converted to bool (Clause 4 [conv]). binary_pred shall not apply any non-constant function through the dereferenced iterators.

  5. Change 25.4 [alg.sorting] p2 as indicated:

    -2- Compare is a function object type (20.9 [function.objects]). The return value of the function call operation applied to an object of type Compare, when implicitly or contextually converted to bool (4 [conv]), yields true if the first argument of the call is less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation. It is assumed that comp will not apply any non-constant function through the dereferenced iterator.

  6. Change 30.2.1 [thread.req.paramname] p2 as indicated:

    -2- If a parameter is Predicate, operator() applied to the actual template argument shall return a value that is convertible to boolPredicate is a function object type (20.9 [function.objects]). The return value of the function call operation applied to an object of type Predicate, when implicitly or contextually converted to bool (4 [conv]), yields true if the corresponding test condition is satisfied, and false otherwise.


2115. Undefined behaviour for valarray assignments with mask_array index?

Section: 26.6.8 [template.mask.array] Status: Open Submitter: Thomas Plum Opened: 2011-12-10 Last modified: 2012-11-14

View all issues with Open status.

Discussion:

Recently I received a Service Request (SR) alleging that one of our testcases causes an undefined behavior. The complaint is that 26.6.8 [template.mask.array] in C++11 (and the corresponding subclause in C++03) are interpreted by some people to require that in an assignment "a[mask] = b", the subscript mask and the rhs b must have the same number of elements.

IMHO, if that is the intended requirement, it should be stated explicitly.

In any event, there is a tiny editorial cleanup that could be made:

In C++11, 26.6.8.1 [template.mask.array.overview] para 2 mentions

"the expression a[mask] = b;"

but the semicolon cannot be part of an expression. The correction could omit the semicolon, or change the word "expression" to "assignment" or "statement".

Here is the text of the SR, slightly modified for publication:

Subject: SR01174 LVS _26322Y31 has undefined behavior [open]

[Client:]
The test case t263.dir/_26322Y31.cpp seems to be illegal as it has an undefined behaviour. I searched into the SRs but found SRs were not related to the topic explained in this mail (SR00324, SR00595, SR00838).

const char vl[] = {"abcdefghijklmnopqrstuvwxyz"};
const char vu[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
const std::valarray<char> v0(vl, 27), vm5(vu, 5), vm6(vu, 6);
std::valarray<char> x = v0;
[…]
const bool vb[] = {false, false, true, true, false, true};
const std::valarray<bool> vmask(vb, 6);
x = v0;
x[vmask] = vm5;      // ***** HERE....
steq(&x[0], "abABeCghijklmnopqrstuvwxyz");
x2 = x[vmask];       // ***** ....AND HERE
[…]

This problem has already been discussed between [experts]: See thread http://gcc.gnu.org/ml/libstdc++/2009-11/threads.html#00051 Conclusion http://gcc.gnu.org/ml/libstdc++/2009-11/msg00099.html

[Plum Hall:]
Before I log this as an SR, I need to check one detail with you.

I did read the email thread you mentioned, and I did find a citation (see INCITS ISO/IEC 14882-2003 Section 26.3.2.6 on valarray computed assignments):

Quote: "If the array and the argument array do not have the same length, the behavior is undefined",

But this applies to computed assignment (*=, +=, etc), not to simple assignment. Here is the C++03 citation re simple assignment:

26.3.2.2 valarray assignment [lib.valarray.assign]

valarray<T>& operator=(const valarray<T>&);

1 Each element of the *this array is assigned the value of the corresponding element of the argument array. The resulting behavior is undefined if the length of the argument array is not equal to the length of the *this array.

In the new C++11 (N3291), we find ...

26.6.2.3 valarray assignment [valarray.assign]

valarray<T>& operator=(const valarray<T>& v);

1 Each element of the *this array is assigned the value of the corresponding element of the argument array. If the length of v is not equal to the length of *this, resizes *this to make the two arrays the same length, as if by calling resize(v.size()), before performing the assignment.

So it looks like the testcase might be valid for C++11 but not for C++03; what do you think?

[Client:]
I quite agree with you but the two problems I mentioned:

x[vmask] = vm5;      // ***** HERE....
[…]
x2 = x[vmask];       // ***** ....AND HERE

refer to mask_array assignment hence target the C++03 26.3.8 paragraph. Correct?

[Plum Hall:]
I mentioned the contrast between C++03 26.3.2.2 para 1 versus C++11 26.6.2.3 para 1.

But in C++03 26.3.8, I don't find any corresponding restriction. Could you quote the specific requirement you're writing about?

[Client:]
I do notice the difference between c++03 26.3.2.2 and c++11 26.6.2.3 about assignments between different sized valarray and I perfectly agree with you.

But, as already stated, this is not a simple valarray assignment but a mask_array assignment (c++03 26.3.8 / c++11 26.6.8). See c++11 quote below:

26.6.8 Class template mask_array
26.6.8.1 Class template mask_array overview
[....]

  1. This template is a helper template used by the mask subscript operator: mask_array<T> valarray<T>::operator[](const valarray<bool>&).

  2. It has reference semantics to a subset of an array specified by a boolean mask. Thus, the expression a[mask] = b; has the effect of assigning the elements of b to the masked elements in a (those for which the corresponding element in mask is true.)

26.6.8.2 mask_array assignment

void operator=(const valarray<T>&) const;
const mask_array& operator=(const mask_array&) const;

1 These assignment operators have reference semantics, assigning the values of the argument array elements to selected elements of the valarray<T> object to which it refers.

In particular, [one of the WG21 experts] insisted on the piece "the elements of b".

That is why I reported the test t263.dir/_26322Y31.cpp having an undefined behaviour.

[Plum Hall:]
OK, I can see that I will have to ask WG21; I will file an appropriate issue with the Library subgroup. In the meantime, I will mark this testcase as "DISPUTED" so that it is not required for conformance testing, until we get a definitive opinion.

[2012, Kona]

Moved to Open.

There appears to be a real need for clarification in the standard, and implementations differ in their current interpretation. This will need some research by implementers and a proposed resolution before further discussion is likely to be fruitful.

Proposed resolution:


2116. std::swap noexcept(what?)

Section: 20.10.4.3 [meta.unary.prop] Status: Open Submitter: Dave Abrahams Opened: 2011-12-09 Last modified: 2012-11-14

View other active issues in [meta.unary.prop].

View all other issues in [meta.unary.prop].

View all issues with Open status.

Discussion:

IMO if we specified is_[nothrow_]constructible in terms of a variable declaration whose validity requires destructibility, it is clearly a bug in our specification and a failure to realize the actual original intent. The specification should have been in terms of placement-new.

Daniel:
At the time of the specification this was intended and the solution is not done by removing the destruction semantics of is_constructible.

The design of is_constructible was also impacted by the previous Constructible concept that explicitly contained destruction semantics, because during conceptification of the library it turned out to simplify the constraints in the library because you did not need to add Destructible all the time. It often was implied but never spoken out in C++03.

Pure construction semantics was considered as useful as well, so HasConstructor did also exist and would surely be useful as trait as well.

Another example that is often overlooked: This also affects wrapper types like pair, tuple, array that contain potentially more than one type: This is easy to understand if you think of T1 having a deleted destructor and T2 having a constructor that may throw: Obviously the compiler has potentially need to use the destructor of T1 in the constructor of std::pair<T1, T2> to ensure that the core language requirements are satisfied (All previous fully constructed sub-objects must be destructed).

The core language also honors this fact in 12.8 [class.copy] p11:

A defaulted copy/move constructor for a class X is defined as deleted (8.4.3 [dcl.fct.def.delete]) if X has:
[…]
— any direct or virtual base class or non-static data member of a type with a destructor that is deleted or inaccessible from the defaulted constructor,
[…]

Dave:
This is about is_nothrow_constructible in particular. The fact that it is foiled by not having a noexcept dtor is a defect.

[2012, Kona]

Move to Open.

is_nothrow_constructible is defined in terms of is_constructible, which is defined by looking at a hypothetical variable and asking whether the variable definition is known not to throw exceptions. The issue claims that this also examines the type's destructor, given the context, and thus will return false if the destructor can potentially throw. At least one implementation (Howard's) does return false if the constructor is noexcept(true) and the destructor is noexcept(false). So that's not a strained interpretation. The issue is asking for this to be defined in terms of placement new, instead of in terms of a temporary object, to make it clearer that is_nothrow_constructible looks at the noexcept status of only the constructor, and not the destructor.

Sketch of what the wording would look like:

require is_constructible, and then also require that a placement new operation does not throw. (Remembering the title of this issue... What does this imply for swap?

If we accept this resolution, do we need any changes to swap?

STL argues: no, because you are already forbidden from passing anything with a throwing desturctor to swap.

Dietmar argues: no, not true. Maybe statically the destructor can conceivably throw for some values, but maybe there are some values known not to throw. In that case, it's correct to pass those values to swap.

Proposed resolution:


2117. ios_base manipulators should have showgrouping/noshowgrouping

Section: 22.4.2.2.2 [facet.num.put.virtuals], 27.5.3.1.2 [ios::fmtflags], 27.5.6.1 [fmtflags.manip] Status: Open Submitter: Benjamin Kosnik Opened: 2011-12-15 Last modified: 2012-11-14

View other active issues in [facet.num.put.virtuals].

View all other issues in [facet.num.put.virtuals].

View all issues with Open status.

Discussion:

Iostreams should include a manipulator to toggle grouping on/off for locales that support grouped digits. This has come up repeatedly and been deferred. See LWG 826 for the previous attempt.

If one is using a locale that supports grouped digits, then output will always include the generated grouping characters. However, very plausible scenarios exist where one might want to output the number, un-grouped. This is similar to existing manipulators that toggle on/off the decimal point, numeric base, or positive sign.

See some user commentary here.

[21012, Kona]

Move to Open.

This is a feature request.

Walter is slightly uncomfortable with processing feature requests through the issues lists.

Alisdair says this is far from the first feature request that has come in from the issues list.

STL: The fact that you can turn off grouping on hex output is compelling.

Marshall: if we add this flag, we'll need to update tables 87-91 as well.

STL: If it has been implemented somewhere, and it works, we'd be glad to add it.

Howard: We need to say what the default is.

Alisdair sumarizes:

(1) We want clear wording that says what the effect is of turning the flag off;

(2) what the default values are, and

(3) how this fits into tables 87-90. (and 128)

Proposed resolution:

This wording is relative to the FDIS.

  1. Insert in 22.4.2.2.2 [facet.num.put.virtuals] paragraph 5:

    Stage 1: The first action of stage 1 is to determine a conversion specifier. The tables that describe this determination use the following local variables

    fmtflags flags = str.flags() ;
    fmtflags basefield = (flags & (ios_base::basefield));
    fmtflags uppercase = (flags & (ios_base::uppercase));
    fmtflags floatfield = (flags & (ios_base::floatfield));
    fmtflags showpos = (flags & (ios_base::showpos));
    fmtflags showbase = (flags & (ios_base::showbase));
    fmtflags showgrouping = (flags & (ios_base::showgrouping));
    
  2. Change header <ios> synopsis, 27.5.1 [iostreams.base.overview] as indicated:

    #include <iosfwd>
    
    namespace std {
      […]
      // 27.5.6, manipulators:
      […]
      ios_base& showpoint     (ios_base& str);
      ios_base& noshowpoint   (ios_base& str);
      ios_base& showgrouping  (ios_base& str);
      ios_base& noshowgrouping(ios_base& str);
      ios_base& showpos       (ios_base& str);
      ios_base& noshowpos     (ios_base& str);
      […]
    }
    
  3. Change class ios_base synopsis, 27.5.3 [ios.base] as indicated:

    namespace std {
      class ios_base {
      public:
      class failure;
        // 27.5.3.1.2 fmtflags
        typedef T1 fmtflags;
        […]
        static constexpr fmtflags showpoint = unspecified ;
        static constexpr fmtflags showgrouping = unspecified ;
        static constexpr fmtflags showpos = unspecified ;
        […]
      };
    }
    
  4. Add a new entry to Table 122 — "fmtflags effects" as indicated:

    Table 122 — fmtflags effects
    Element Effect(s) if set
    […]
    showpoint generates a decimal-point character unconditionally in generated floatingpoint output
    showgrouping generates grouping characters unconditionally in generated output
    […]
  5. After 27.5.3.1.2 [ios::fmtflags] p12 insert the following:

    ios_base& showgrouping(ios_base& str);
    

    -?- Effects: Calls str.setf(ios_base::showgrouping).

    -?- Returns: str.

    ios_base& noshowgrouping(ios_base& str);
    

    -?- Effects: Calls str.unsetf(ios_base::showgrouping).

    -?- Returns: str.


2118. [CD] unique_ptr for array does not support cv qualification conversion of actual argument

Section: 20.8.1.3 [unique.ptr.runtime] Status: Open Submitter: Alf P. Steinbach Opened: 2011-12-16 Last modified: 2013-10-15

View all other issues in [unique.ptr.runtime].

View all issues with Open status.

Discussion:

Addresses US 16

N3290 20.8.1.3.1 [unique.ptr.runtime.ctor] "unique_ptr constructors":

These constructors behave the same as in the primary template except that they do not accept pointer types which are convertible to pointer. [Note: One implementation technique is to create private templated overloads of these members. — end note]

This language excludes even pointer itself as type for the actual argument.

But of more practical concern is that both Visual C++ 10.0 and MinGW g++ 4.1.1 reject the code below, where only an implicit cv qualification is needed, which cv qualification is supported by the non-array version:

#include <memory>
using namespace std;

struct T {};

T* foo() { return new T; }
T const* bar() { return foo(); }

int main()
{
   unique_ptr< T const >       p1( bar() );        // OK
   unique_ptr< T const [] >    a1( bar() );        // OK

   unique_ptr< T const >       p2( foo() );        // OK
   unique_ptr< T const [] >    a2( foo() );        // ? this is line #15
}

The intent seems to be clearly specified in 20.8.1.3 [unique.ptr.runtime]/1 second bullet:

— Pointers to types derived from T are rejected by the constructors, and by reset.

But the following language in 20.8.1.3.1 [unique.ptr.runtime.ctor] then rejects far too much...

Proposed new wording of N3290 20.8.1.3.1 [unique.ptr.runtime.ctor] "unique_ptr constructors":

These constructors behave the same as in the primary template except that actual argument pointers p to types derived from T are rejected by the constructors. [Note: One implementation technique is to create private templated overloads of these members. — end note]

This will possibly capture the intent better, and avoid the inconsistency between the non-array and array versions of unique_ptr, by using nearly the exact same phrasing as for the paragraph explaining the intent.

[2012-08-25 Geoffrey Romer comments in c++std-lib-32978]

  1. The current P/R seems to intend to support at least two different implementation techniques — additional unusable templates that catch forbidden arguments or replacing existing constructors by templates that ensure ill-formed code inside the template body, when the requirements are not met. It seems unclear whether the current wording allows the second approach, though. It should be considered to allow both strategies or if that is not possible the note should be clearer.

  2. The very same problem exists for the reset member function, but even worse, because the current specification is more than clear that the deleted reset function will catch all cases not equal to pointer. It seems confusing at best to have different policies for the constructor and for the reset function. In this case, the question in regard to implementation freedom mentioned above is even more important.

  3. It's awkward to refer to "the constructors" twice in the same sentence; I suggest revising the sentence as "...except that they do not accept argument pointers p to types derived from T"

[2012-12-20: Geoffrey Romer comments and provides a revised resolution]

The array specialization of unique_ptr differs from the primary template in several ways, including the following:

The common intent of all these restrictions appears to be to disallow implicit conversions from pointer-to-derived-class to pointer-to-base-class in contexts where the pointer is known to point to an array, because such conversions are inherently unsafe; deleting or subscripting the result of such a conversion leads to undefined behavior (see also CWG 1504). However, these restrictions have the effect of disallowing all implicit conversions in those contexts, including most notably cv-qualification, but also user-defined conversions, and possibly others. This PR narrows all those restrictions, to disallow only unsafe pointer-to-derived to pointer-to-base conversions, while allowing all others.

I removed the nebulous language stating that certain functions "will not accept" certain arguments. Instead I use explicitly deleted template functions, which participate in overload resolution only for pointer-to-derived to pointer-to-base conversions. This is more consistent with the existing text and easier to express correctly than an approach based on declaring certain types of calls to be ill-formed, but may produce inferior compiler diagnostics.

Wherever possible, this PR defines the semantics of template specializations in terms of their differences from the primary template. This improves clarity and minimizes the risk of unintended differences (e.g. LWG 2169, which this PR also fixes). This PR also makes it explicit that the specialization inherits the description of all members, not just member functions, from the primary template and, in passing, clarifies the default definition of pointer in the specialization.

This resolution only disallows pointer-to-derived to pointer-to-base conversions between ordinary pointer types; if user-defined pointer types provide comparable conversions, it is their responsibility to ensure they are safe. This is consistent with C++'s general preference for expressive power over safety, and for assuming the user knows what they're doing; furthermore, enforcing such a restriction on user-defined types appears to be impractical without cooperation from the user.

The "base class without regard to cv-qualifiers" language is intended to parallel the specification of std::is_base_of.

Jonathan Wakely has a working implementation of this PR patched into libstdc++.

Previous resolution:

This wording is relative to the FDIS.

Change 20.8.1.3.1 [unique.ptr.runtime.ctor] as indicated:

explicit unique_ptr(pointer p) noexcept;
unique_ptr(pointer p, see below d) noexcept;
unique_ptr(pointer p, see below d) noexcept;

These constructors behave the same as in the primary template except that they do not accept pointer types which are convertible to pointerargument pointers p to types derived from T are rejected by the constructors. [Note: One implementation technique is to create private templated overloads of these members. — end note]

Proposed resolution:

This wording is relative to N3485.

  1. Revise 20.8.1.1.3 [unique.ptr.dltr.dflt1] as follows

    namespace std {
      template <class T> struct default_delete<T[]> {
        constexpr default_delete() noexcept = default;
        template <class U> default_delete(const default_delete<U>&) noexcept;
        void operator()(T*) const;
        template <class U> void operator()(U*) const = delete;
      };
    }
    

    -?- Descriptions are provided below only for member functions that have behavior different from the primary template.

    template <class U> default_delete(const default_delete<U>&) noexcept;
    

    -?- This constructor behaves the same as in the primary template except that it shall not participate in overload resolution unless:

    • U is an array type, and

    • V* is implicitly convertible to T*, and

    • T is not a base class of V (without regard to cv-qualifiers),

    where V is the array element type of U.

    void operator()(T* ptr) const;
    

    -1- Effects: calls delete[] on ptr.

    -2- Remarks: If T is an incomplete type, the program is ill-formed.

    template <class U> void operator()(U*) const = delete;
    

    -?- Remarks: This function shall not participate in overload resolution unless T is a base class of U (without regard to cv-qualifiers).

  2. Revise 20.8.1.2 [unique.ptr.single]/3 as follows:

    If the type remove_reference<D>::type::pointer exists, then unique_ptr<T, D>::pointer shall be a synonym for remove_reference<D>::type::pointer. Otherwise unique_ptr<T, D>::pointer shall be a synonym for Telement_type*. The type unique_ptr<T, D>::pointer shall satisfy the requirements of NullablePointer (17.6.3.3 [nullablepointer.requirements]).

  3. Revise 20.8.1.3 [unique.ptr.runtime] as follows:

    namespace std {
      template <class T, class D> class unique_ptr<T[], D> {
      public:
        typedef see below pointer;
        typedef T element_type;
        typedef D deleter_type;
    
        // 20.7.1.3.1, constructors
        constexpr unique_ptr() noexcept;
        explicit unique_ptr(pointer p) noexcept;
        template <class U> explicit unique_ptr(U* p) = delete;
        unique_ptr(pointer p, see below d) noexcept;
        template <class U> unique_ptr(U* p, see below d) = delete;
        unique_ptr(pointer p, see below d) noexcept;
        template <class U> unique_ptr(U* p, see below d) = delete;
        unique_ptr(unique_ptr&& u) noexcept;
        constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { }
        template <class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
    
        // destructor
        ~unique_ptr();
    
        // assignment
        unique_ptr& operator=(unique_ptr&& u) noexcept;
        template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
        unique_ptr& operator=(nullptr_t) noexcept;
    
        // 20.7.1.3.2, observers
        T& operator[](size_t i) const;
        pointer get() const noexcept;
        deleter_type& get_deleter() noexcept;
        const deleter_type& get_deleter() const noexcept;
        explicit operator bool() const noexcept;
    
        // 20.7.1.3.3 modifiers
        pointer release() noexcept;
        void reset(pointer p = pointer()) noexcept;
        void reset(nullptr_t) noexcept;
        template <class U> void reset(U*) = delete;
        void swap(unique_ptr& u) noexcept;
    
        // disable copy from lvalue
        unique_ptr(const unique_ptr&) = delete;
        unique_ptr& operator=(const unique_ptr&) = delete;
      };
    }
    

    -1- A specialization for array types is provided with a slightly altered interface.

    • Conversions between different types of unique_ptr<T[], D>from unique_ptr<Derived[]> to unique_ptr<Base[]>, where Base is a base class of Derived, from auto_ptr, or to or from the non-array forms of unique_ptr produce an ill-formed program.

    • Pointers to types derived from T are rejected by the constructors, and by reset.

    • The observers operator* and operator-> are not provided.

    • The indexing observer operator[] is provided.

    • The default deleter will call delete[].

    -2- Descriptions are provided below only for member functions that have behavior differentmembers that differ from the primary template.

    -3- The template argument T shall be a complete type.

  4. Revise 20.8.1.3.1 [unique.ptr.runtime.ctor] as follows:

    explicit unique_ptr(pointer p) noexcept;
    unique_ptr(pointer p, see below d) noexcept;
    unique_ptr(pointer p, see below d) noexcept;
    template <class U> explicit unique_ptr(U* p) = delete;
    template <class U> unique_ptr(U* p, see below d) = delete;
    template <class U> unique_ptr(U* p, see below d) = delete;
    

    These constructors behave the same as in the primary template except that they do not accept pointer types which are convertible to pointer. [Note: One implementation technique is to create private templated overloads of these members. — end note]These constructors shall not participate in overload resolution unless:

    • pointer is a pointer type, and

    • U* is implicitly convertible to pointer, and

    • T is a base class of U (without regard to cv-qualifiers).

    The type of d is determined as in the corresponding non-deleted constructors.

    template <class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
    

    -?- This constructor behaves the same as in the primary template, except that it shall not participate in overload resolution unless:

    • unique_ptr<U, E>::pointer is implicitly convertible to pointer, and

    • U is an array type, and

    • either D is a reference type and E is the same type as D, or D is not a reference type and E is implicitly convertible to D, and

    • either at least one of pointer and unique_ptr<U, E>::pointer is not a pointer type, or T is not a base class of the array element type of U (without regard to cv-qualifiers).

  5. Insert a new sub-clause following 20.8.1.3.1 [unique.ptr.runtime.ctor] as follows:

    ?? unique_ptr assignment [unique.ptr.runtime.asgn]

    template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
    

    -?- This operator behaves the same as in the primary template, except that it shall not participate in overload resolution unless:

    • unique_ptr<U, E>::pointer is implicitly convertible to pointer, and

    • U is an array type, and

    • either D is a reference type and E is the same type as D, or D is not a reference type and E is implicitly convertible to D, and

    • either at least one of pointer and unique_ptr<U, E>::pointer is not a pointer type, or T is not a base class of the array element type of U (without regard to cv-qualifiers).

  6. Revise 20.8.1.3.3 [unique.ptr.runtime.modifiers] as follows:

    void reset(pointer p = pointer()) noexcept;
    void reset(nullptr_t p) noexcept;
    template <class U> void reset(U*) = delete;
    

    -1- Effects: If get() == nullptr there are no effects. Otherwise get_deleter()(get()).

    -2- Postcondition: get() == p.

    -?- This function shall not participate in overload resolution unless:

    • pointer is a pointer type, and

    • U* is implicitly convertible to pointer, and

    • T is a base class of U (without regard to cv-qualifiers).


2119. Missing hash specializations for extended integer types

Section: 20.9.12 [unord.hash] Status: Open Submitter: Daniel Krügler Opened: 2011-12-16 Last modified: 2012-11-14

View all other issues in [unord.hash].

View all issues with Open status.

Discussion:

According to the header <functional> synopsis 20.9 [function.objects] and to the explicit description in 20.9.12 [unord.hash] class template hash specializations shall be provided for all arithmetic types that are not extended integer types. This is not explicitly mentioned, but neither the list nor any normative wording does include them, so it follows by implication.

What are the reasons that extended integer types are excluded? E.g. for numeric_limits corresponding specializations are required. I would expect that an unordered_map with key type std::uintmax_t would just work, but that depends now on whether this type is an extended integer type or not.

This issue is not asking for also providing specializations for the cv-qualified arithmetic types. While this is surely a nice-to-have feature, I consider that restriction as a more secondary problem in practice.

The proposed resolution also fixes a problem mentioned in 2109 in regard to confusing requirements on user-defined types and those on implementations.

[2012, Kona]

Move to Open.

Agreed that it's a real issue and that the proposed wording fixes it. However, the wording change is not minimal and isn't consistent with the way we fixed hash wording elsewhere.

Alisdair will provide updated wording.

Proposed resolution:

This wording is relative to the FDIS.

Change 20.9.12 [unord.hash] p2 as indicated:

template <> struct hash<bool>;
template <> struct hash<char>;
[…]
template <> struct hash<long double>;
template <class T> struct hash<T*>;

-2- Requires: the template specializations shall meet the requirements of class template hash (20.9.12 [unord.hash])The header <functional> provides definitions for specializations of the hash class template for each cv-unqualified arithmetic type. This header also provides a definition for a partial specialization of the hash class template for any pointer type. The requirements for the members of these specializations are given in sub-clause 20.9.12 [unord.hash].


2121. app for string streams

Section: 27.8.6 [stringstream.cons] Status: New Submitter: Nicolai Josuttis Opened: 2012-01-15 Last modified: 2012-11-14

View all issues with New status.

Discussion:

This issue was raised while discussing issue 1448.

Note the following program:

string s("s1: 123456789");
ostringstream s1(s, ios_base::out|ios_base::app);
s1 << "hello";
cout << s1.str() << endl;

With g++4.x it prints:

s1: 123456789hello

With VisualC++10 it prints:

hello23456789

From my intuitive understanding the flag "app" should result in the output of g++4.x. I also would read that from 27.5.3.1.4 [ios::openmode] claiming:

app   seek to end before each write

However in issue 1448 P.J.Plauger comments:

I think we should say nothing special about app at construction time (thus leaving the write pointer at the beginning of the buffer). Leave implementers wiggle room to ensure subsequent append writes as they see fit, but don't change existing rules for initial seek position.

Note that the flag ate on both platforms appends "hello" to s.

Proposed resolution:


2125. TimedMutex specification problem

Section: 30.4.1.3 [thread.timedmutex.requirements], 30.4.1.3.1 [thread.timedmutex.class] Status: Tentatively NAD Editorial Submitter: Vicente J. Botet Escriba Opened: 2012-01-01 Last modified: 2013-10-15

View all other issues in [thread.timedmutex.requirements].

View all issues with Tentatively NAD Editorial status.

Discussion:

30.4.1.3.1 [thread.timedmutex.class] says:

The class timed_mutex shall satisfy all of the TimedMutex requirements (30.4.1.3 [thread.timedmutex.requirements]). It shall be a standardlayout class (Clause 9 [class]).

Problem here is that 30.4.1.3 [thread.timedmutex.requirements] does not define a requirement set named "TimedMutex", it only refers to "timed mutex types"

[See also issue 2126]

[2012, Portland: move to Tentatively NAD Editorial]

We have timed mutex type, but it is labeled timed mutex requirements

We can make a suggestion, but will send to the editor as it seems purely editorial. There is a typo, and we don't have the timed mutex but 30.4.1.3 [thread.timedmutex.requirements] already says timed mutex type, and we need to reuse that term down in the class to fulfil the mutex requirement.

[To Editor:]

Replace this one with timed mutex type.

Proposed resolution:


2126. Several specification problems in regard to mutex requirements

Section: 30.4.1 [thread.mutex.requirements], 30.4.1.2.1 [thread.mutex.class], 30.4.1.2 [thread.mutex.requirements.mutex], 30.4.1.2.2 [thread.mutex.recursive], 30.4.1.3 [thread.timedmutex.requirements], 30.4.1.3.1 [thread.timedmutex.class], 30.4.1.3.2 [thread.timedmutex.recursive] Status: Tentatively NAD Editorial Submitter: Pete Becker Opened: 2012-01-16 Last modified: 2013-10-15

View all other issues in [thread.mutex.requirements].

View all issues with Tentatively NAD Editorial status.

Discussion:

30.4.1.2.1 [thread.mutex.class]/3 says that the class mutex "shall satisfy all the Mutex requirements (30.4.1 [thread.mutex.requirements])". 30.4.1.2.1 [thread.mutex.class] is part of 30.4.1 [thread.mutex.requirements], so at the very least, this requirement is recursive. But worse, there is nothing that says what "the Mutex requirements" refers to. For example, the "Lockable requirements" section starts with "A type L meets the Lockable requirements if …". There is no such statement for "the Mutex requirements".

Organizationally, paragraphs 1-26 in 30.4.1.2 [thread.mutex.requirements.mutex] should probably be in a subclause with a name. (This is actually an ISO requirement, to avoid exactly this kind of ambiguous referencing) Then the first sentence of 30.4.1.2.1 [thread.mutex.class]/3 can become a note: "The class mutex meets the requirements of (whatever)", since that subclause already says that the mutex types "shall meet the requirements set out in this section."

And similarly for 30.4.1.2.2 [thread.mutex.recursive]/2 (recursive_mutex).

30.4.1.3 [thread.timedmutex.requirements], Timed mutex types, also needs the same rearrangement: its introductory requirements should be moved into a subclause, and the first sentences of 30.4.1.3.1 [thread.timedmutex.class]/2 and 30.4.1.3.2 [thread.timedmutex.recursive]/2 should be turned into notes that refer to this new subclause and to the new subclause in 30.4.1.2 [thread.mutex.requirements.mutex].

[See also issue 2125]

[2012, Portland: move to Tentatively NAD Editorial]

Seems no real ambiguity. May need some reorg of text rather then changing the wording.

Is there much that needs to be changed? But Pete's suggestion of putting requirement in separate sub section is good. Should be the direction to editor.

Suggest this is an editorial change. Happy with Pete's comments.

Proposed resolution:


2127. Move-construction with raw_storage_iterator

Section: 20.7.10 [storage.iterator] Status: Open Submitter: Jonathan Wakely Opened: 2012-01-23 Last modified: 2012-11-14

View all other issues in [storage.iterator].

View all issues with Open status.

Discussion:

Aliaksandr Valialkin pointed out that raw_storage_iterator only supports constructing a new object from lvalues so cannot be used to construct move-only types:

template <typename InputIterator, typename T>
void move_to_raw_buffer(InputIterator first, InputIterator last, T *raw_buffer)
{
  std::move(first, last, std::raw_storage_iterator<T *, T>(raw_buffer));
}

This could easily be solved by overloading operator= for rvalues.

Dave Abrahams:

raw_storage_iterator causes exception-safety problems when used with any generic algorithm. I suggest leaving it alone and not encouraging its use.

Proposed resolution:

This wording is relative to N3337.

  1. Add a new signature to the synopsis in 20.7.10 [storage.iterator] p1:

    namespace std {
      template <class OutputIterator, class T>
      class raw_storage_iterator
        : public iterator<output_iterator_tag,void,void,void,void> {
      public:
        explicit raw_storage_iterator(OutputIterator x);
    
        raw_storage_iterator<OutputIterator,T>& operator*();
        raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
        raw_storage_iterator<OutputIterator,T>& operator=(T&& element);
        raw_storage_iterator<OutputIterator,T>& operator++();
        raw_storage_iterator<OutputIterator,T> operator++(int);
    };
    }
    
  2. Insert the new signature and a new paragraph before p4:

    raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
    raw_storage_iterator<OutputIterator,T>& operator=(T&& element);
    

    -?- Requires: For the first signature T shall be CopyConstructible. For the second signature T shall be MoveConstructible.

    -4- Effects: Constructs a value from element at the location to which the iterator points.

    -5- Returns: A reference to the iterator.


2129. User specializations of std::initializer_list

Section: 17.6.4.2.1 [namespace.std], 18.9 [support.initlist] Status: Open Submitter: Richard Smith Opened: 2012-01-18 Last modified: 2012-11-14

View other active issues in [namespace.std].

View all other issues in [namespace.std].

View all issues with Open status.

Discussion:

Since the implementation is intended to magically synthesize instances of std::initializer_list (rather than by a constructor call, for instance), user specializations of this type can't generally be made to work. I can't find any wording which makes such specializations ill-formed, though, which leads me to suspect that they're technically legal under the provisions of 17.6.4.2.1 [namespace.std] p1.

[2012, Kona]

This sounds correct, but we need wording for a resultion.

Marshall Clow volunteers to produce wording.

Proposed resolution:


2131. Member function getline taking a string as parameter

Section: 27.7.2.3 [istream.unformatted] Status: Tentatively NAD Submitter: Loïc Joly Opened: 2012-03-05 Last modified: 2013-10-15

View other active issues in [istream.unformatted].

View all other issues in [istream.unformatted].

View all issues with Tentatively NAD status.

Discussion:

I think the following code should be legal:

void f(std::istream& is)
{
  std::string s;
  is.getline(s); // Would be equivalent to std::getline(is, s)
}

[2013-04-20, Bristol]

Unanimous that this is a new feature request and not a issue.

Resolution: Tentatively NAD

Proposed resolution:

This wording is relative to N3376.

  1. Change the class template basic_istream synopsis, 27.7.2.1 [istream], as indicated

    namespace std {
      template <class charT, class traits = char_traits<charT> >
      class basic_istream : virtual public basic_ios<charT,traits> {
      public:
        […]
        // 27.7.2.3 Unformatted input:
        […]
        basic_istream<charT,traits>& getline(char_type* s, streamsize n);
        basic_istream<charT,traits>& getline(char_type* s, streamsize n,
          char_type delim);
        template<class Allocator>
        basic_istream<charT,traits>& getline(basic_string<charT,traits,Allocator>& str);
        template<class Allocator>
        basic_istream<charT,traits>& getline(basic_string<charT,traits,Allocator>& str,
          char_type delim);
        […]
      };
    }
    
  2. Insert the following two new prototype descriptions after 27.7.2.3 [istream.unformatted] paragraph 24:

    basic_istream<charT,traits>& getline(char_type* s, streamsize n);
    

    -24- Returns: getline(s,n,widen('\n'))

    template<class Allocator>
    basic_istream<charT,traits>& getline(basic_string<charT,traits,Allocator>& str);
    

    -??- Returns: std::getline(*this, str)

    template<class Allocator>
    basic_istream<charT,traits>& getline(basic_string<charT,traits,Allocator>& str, char_type delim);
    

    -??- Returns: std::getline(*this, str, delim)


2132. std::function ambiguity

Section: 20.9.11.2.1 [func.wrap.func.con] Status: Review Submitter: Ville Voutilainen Opened: 2012-02-28 Last modified: 2013-10-15

View all other issues in [func.wrap.func.con].

View all issues with Review status.

Discussion:

Consider the following:

#include <functional>

void f(std::function<void()>) {}
void f(std::function<void(int)>) {}

int main() {
  f([]{});
  f([](int){});
}

The calls to f in main are ambiguous. Apparently because the conversion sequences to std::function from the lambdas are identical. The standard specifies that the function object given to std::function "shall be Callable (20.8.11.2) for argument types ArgTypes and return type R." It doesn't say that if this is not the case, the constructor isn't part of the overload set.

Daniel: During the preparation of N3123 it turned out that there are no longer reasons to refer to INVOKE as a conceptually entity alone, its real implementation as a function template invoke is possible but was deferred for a later point in time. Defining a type trait for the Callable requirement would also be possible, so there seem to be no technical reasons why the template constructor of std::function should not be constrained. The below suggested wording does this without introducing a special trait for this. This corresponds to the way that has been used to specify the result_of trait. Note that the definition of the Callable requirement is perfectly suitable for this, because it is a pure syntactically based requirement and can be directly transformed into a constrained template.

The suggested resolution also applies such wording to the "perfectly forwarding" assignment operator

template<class F> function& operator=(F&&);

The positive side-effect of this is that it automatically implements a solution to a problem similar to that mentioned in issue 1234.

It would be possible to apply similar constraints to the member signatures

template<class F> function& operator=(reference_wrapper<F>);

template<class F, class A> void assign(F&&, const A&);

as well. At this point there does not seem to be a pestering reason to do so.

[2012-10 Portland: Move to Review]

STL: This is a real issue, but does not like a resolution relying on a SFINAEable metafunction that is not specified and available to the users.

packaged_task has the same issue.

STL strongly wants to see an is_callable type trait to clarify the proposed wording.

Jeremiah concerned about holding up what appears to be a correct resolution for a hypothetical better one later - the issue is real.

Why must f by CopyConstructible? Surely MoveConstructible would be sufficient?

Answer: because function is CopyConstructible, and the bound functor is type-erased so must support all the properties of function itself.

Replace various applications of declval in the proposed resolution with simply using the passed functor object, f.

Alisdair to apply similar changes to packaged_task.

[2012-11-09, Vicente J. Botet Escriba provides another example]

Consider the following:

class AThreadWrapper {
public:
  explicit operator std::thread();
  ...
};
std::thread th = std::thread(AThreadWrapper); // call to conversion operator intended

The call to the conversion operator is overloaded with the thread constructor. But thread constructor requirement makes it fail as AThreadWrapper is not a Callable and the compiler tries to instantiate the thread constructor and fails.

Proposed resolution:

This wording is relative to N3376.

  1. Change the following paragraphs in 20.9.11.2.1 [func.wrap.func.con]: [Editorial comment: The removal of the seemingly additional no-throw requirements of copy constructor and destructor of A is recommended, because they are already part of the Allocator requirements. Similar clean-up has been suggested by 2070end comment]

    template<class F> function(F f);
    template<class F, class A> function(allocator_arg_t, const A& a, F f);
    

    -7- Requires: F shall be CopyConstructible. f shall be Callable (20.9.11.2 [func.wrap.func]) for argument types ArgTypes and return type R. The copy constructor and destructor of A shall not throw exceptions.

    -?- Remarks: These constructors shall not participate in overload resolution unless f is Callable (20.9.11.2 [func.wrap.func]) for argument types ArgTypes... and return type R.

    […]

    template<class F> function& operator=(F&& f);
    

    -18- Effects: function(std::forward<F>(f)).swap(*this);

    -19- Returns: *this

    -?- Remarks: This assignment operator shall not participate in overload resolution unless declval<typename decay<F>::type&>() is Callable (20.9.11.2 [func.wrap.func]) for argument types ArgTypes... and return type R.


2133. Attitude to overloaded comma for iterators

Section: 17.6.5.4 [global.functions] Status: Open Submitter: Yakov Galka Opened: 2012-01-25 Last modified: 2013-10-15

View all other issues in [global.functions].

View all issues with Open status.

Discussion:

17.6.5.4 [global.functions] says

Unless otherwise specified, global and non-member functions in the standard library shall not use functions from another namespace which are found through argument-dependent name lookup (3.4.2).

This sounds clear enough. There are just two problems:

  1. Both implementations I tested (VS2005 and GCC 3.4.3) do unqualified calls to the comma operator in some parts of the library with operands of user-defined types.

  2. The standard itself does this in the description of some algorithms. E.g. uninitialized_copy is defined as:

    Effects:

    for (; first != last; ++result, ++first)
      ::new (static_cast<void*>(&*result))
        typename iterator_traits<ForwardIterator>::value_type(*first);
    

If understood literally, it is required to call operator,(ForwardIterator, InputIterator).

For detailed discussion with code samples see here.

Proposal:

  1. Add an exception to the rule in 17.6.5.4 [global.functions] by permitting the implementation to call the comma operator as much as it wants to. I doubt we want this. or
  2. Fix the description of the said algorithms and perhaps add a note to 17.6.5.4 [global.functions] that brings attention of the implementers to avoid this pitfall.

[2013-03-15 Issues Teleconference]

Moved to Open.

There are real questions here, that may require a paper to explore and answer properly.

Proposed resolution:


2134. Redundant Mutex requirement?

Section: 30.4.1.2 [thread.mutex.requirements.mutex] Status: Tentatively NAD Editorial Submitter: Pete Becker Opened: 2012-03-05 Last modified: 2013-10-15

View other active issues in [thread.mutex.requirements.mutex].

View all other issues in [thread.mutex.requirements.mutex].

View all issues with Tentatively NAD Editorial status.

Discussion:

30.4.1.2 [thread.mutex.requirements.mutex]/11 says that prior unlock operations synchronize with m.lock().

30.4.1.2 [thread.mutex.requirements.mutex]/19 says that if m.try_lock() succeeds, prior unlock operations synchronize with the operation.

30.4.1.2 [thread.mutex.requirements.mutex]/25 says that m.unlock() synchronizes with subsequent successful lock operations.

Does the third requirement add anything to the first two? If not, it should probably be a non-normative note.

[2012, Portland: move to Tentatively NAD Editorial]

Agree that third note should be non-normative and adds nothing.

Seems An Editorial change, but does changing a normative to non-normative wording makes it a non-editorial change?

Ask the editor. If not editorial, then we will agree on the fix as removal of the third point, then we will put it in ready state for Bristol.

Proposed resolution:


2135. Unclear requirement for exceptions thrown in condition_variable::wait()

Section: 30.5.1 [thread.condition.condvar], 30.5.2 [thread.condition.condvarany] Status: Ready Submitter: Pete Becker Opened: 2012-03-06 Last modified: 2013-10-15

View other active issues in [thread.condition.condvar].

View all other issues in [thread.condition.condvar].

View all issues with Ready status.

Discussion:

condition_varible::wait() (and, presumably, condition_variable_any::wait(), although I haven't looked at it) says that it calls lock.unlock(), and if condition_variable::wait() exits by an exception it calls lock.lock() on the way out. But if the initial call to lock.unlock() threw an exception, does it make sense to call lock.lock()? We simply don't know the state of that lock object, and it's probably better not to touch it.

That aside, once the wait() call has been unblocked, it calls lock.lock(). If lock.lock() throws an exception, what happens? The requirement is:

If the function exits via an exception, lock.lock() shall be called prior to exiting the function scope.

That can be read in two different ways. One way is as if it said "lock.lock() shall have been called …", i.e. the original, failed, call to lock.lock() is all that's required. But a more natural reading is that wait has to call lock.lock() again, even though it already failed.

I think this wording suffers from being too general. There are two possible exception sources: the initial call to lock.unlock() and the final call to lock.lock(). Each one should have its own requirement. Lumping them together muddles things.

[2012, Portland: move to Open]

Pablo: unlock failing is easy -- the call leaves it locked. The second case, trying to lock fails -- what can you do? This is an odd state as we had it locked before was called wait. Maybe we should call terminate as we cannot meet the post-conditions. We could throw a different exception.

Hans: calling terminate makes sense as we're likely to call it soon anyway and at least we have some context.

Detlef: what kind of locks might be being used?

Pablo: condition variables are 'our' locks so this is less of a problem. condition_variable_any might be more problematic.

The general direction is to call terminate if the lock cannot be reacquired.

Pablo: Can we change the wording to 'leaves the mutex locked' ?

Hans: so if the unlock throws we simply propagate the exception.

Move the issue to open and add some formal wording at a later time.

[2013-09 Chicago: Resolved]

Detlef improves wording. Daniel suggests to introduce a Remarks element for the special "If the function fails to meet the postcondition..." wording and applies this to the proposed wording.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 30.5.1 [thread.condition.condvar] as indicated:

    void wait(unique_lock<mutex>& lock);
    

    […]

    -10- Effects:

    • Atomically calls lock.unlock() and blocks on *this.

    • When unblocked, calls lock.lock() (possibly blocking on the lock), then returns.

    • The function will unblock when signaled by a call to notify_one() or a call to notify_all(), or spuriously.

    • If the function exits via an exception, lock.lock() shall be called prior to exiting the function scope.

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -11- Postcondition: lock.owns_lock() is true and lock.mutex() is locked by the calling thread.

    -12- Throws: Nothingsystem_error when an exception is required (30.2.2).

    -13- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

    template <class Predicate>
    void wait(unique_lock<mutex>& lock, Predicate pred);
    

    […]

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -16- Postcondition: lock.owns_lock() is true and lock.mutex() is locked by the calling thread.

    -17- Throws: system_error when an exception is required (30.2.2), timeout-related exceptions (30.2.4), or any exception thrown by pred.

    -18- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

    template <class Clock, class Duration>
      cv_status wait_until(unique_lock<mutex>& lock,
        const chrono::time_point<Clock, Duration>& abs_time);
    

    […]

    -20- Effects:

    • […]

    • If the function exits via an exception, lock.lock() shall be called prior to exiting the function scope.

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -21- Postcondition: lock.owns_lock() is true and lock.mutex() is locked by the calling thread.

    […]

    -23- Throws: system_error when an exception is required (30.2.2) or timeout-related exceptions (30.2.4).

    -24- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

    template <class Rep, class Period>
      cv_status wait_for(unique_lock<mutex>& lock,
        const chrono::duration<Rep, Period>& rel_time);
    

    […]

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -28- Postcondition: lock.owns_lock() is true and lock.mutex() is locked by the calling thread.

    […]

    -29- Throws: system_error when an exception is required (30.2.2) or timeout-related exceptions (30.2.4).

    -30- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

    template <class Clock, class Duration, class Predicate>
      bool wait_until(unique_lock<mutex>& lock,
        const chrono::time_point<Clock, Duration>& abs_time,
    	Predicate pred);
    

    […]

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -33- Postcondition: lock.owns_lock() is true and lock.mutex() is locked by the calling thread.

    […]

    -35- Throws: system_error when an exception is required (30.2.2), timeout-related exceptions (30.2.4), or any exception thrown by pred.

    -36- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

    template <class Rep, class Period, class Predicate>
      bool wait_for(unique_lock<mutex>& lock,
        const chrono::duration<Rep, Period>& rel_time,
    	Predicate pred);
    

    […]

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -40- Postcondition: lock.owns_lock() is true and lock.mutex() is locked by the calling thread.

    […]

    -42- Throws: system_error when an exception is required (30.2.2), timeout-related exceptions (30.2.4), or any exception thrown by pred.

    -43- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

  2. Edit 30.5.2 [thread.condition.condvarany] as indicated:

    template<class Lock>
    void wait(Lock& lock);
    

    […]

    -10- Effects:

    • Atomically calls lock.unlock() and blocks on *this.

    • When unblocked, calls lock.lock() (possibly blocking on the lock) and returns.

    • The function will unblock when signaled by a call to notify_one(), a call to notify_all(), or spuriously.

    • If the function exits via an exception, lock.lock() shall be called prior to exiting the function scope.

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -11- Postcondition: lock is locked by the calling thread.

    -12- Throws: Nothingsystem_error when an exception is required (30.2.2).

    -13- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

    template <class Lock, class Clock, class Duration>
      cv_status wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time);
    

    […]

    -15- Effects:

    • […]

    • If the function exits via an exception, lock.lock() shall be called prior to exiting the function scope.

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -16- Postcondition: lock is locked by the calling thread.

    […]

    -18- Throws: system_error when an exception is required (30.2.2) or timeout-related exceptions (30.2.4).

    -19- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().

    template <class Lock, class Rep, class Period>
      cv_status wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time);
    

    […]

    -?- Remarks: If the function fails to meet the postcondition, std::terminate() shall be called (15.5.1 [except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. — end note]

    -22- Postcondition: lock is locked by the calling thread.

    […]

    -23- Throws: system_error when an exception is required (30.2.2) or timeout-related exceptions (30.2.4).

    -24- Error conditions:

    • equivalent error condition from lock.lock() or lock.unlock().


2136. Postconditions vs. exceptions

Section: 17.5.1 [structure] Status: Open Submitter: Jens Maurer Opened: 2012-03-08 Last modified: 2012-11-14

View all issues with Open status.

Discussion:

The front matter in clause 17 should clarify that postconditions will not hold if a standard library function exits via an exception. Postconditions or guarantees that apply when an exception is thrown (beyond the basic guarantee) are described in an "Exception safety" section.

[ 2012-10 Portland: Move to Open ]

Consensus that we do not clearly say this, and that we probably should. A likely location to describe the guarantees of postconditions could well be a new sub-clause following 17.6.4.11 [res.on.required] which serves the same purpose for requires clauses. However, we need such wording before we can make progress.

Also, see 2137 for a suggestion that we want to see a paper resolving both issues together.

Proposed resolution:


2137. Misleadingly constrained post-condition in the presence of exceptions

Section: 28.8.3 [re.regex.assign] Status: Open Submitter: Jonathan Wakely Opened: 2012-03-08 Last modified: 2012-11-14

View all other issues in [re.regex.assign].

View all issues with Open status.

Discussion:

The post-conditions of basic_regex<>::assign 28.8.3 [re.regex.assign] p16 say:

If no exception is thrown, flags() returns f and mark_count() returns the number of marked sub-expressions within the expression.

The default expectation in the library is that post-conditions only hold, if there is no failure (see also 2136), therefore the initial condition should be removed to prevent any misunderstanding.

[ 2012-10 Portland: Move to Open ]

A favorable resolution clearly depends on a favorable resolution to 2136. There is also a concern that this is just one example of where we would want to apply such a wording clean-up, and which is really needed to resolve both this issue and 2136 is a paper providing the clause 17 wording that gives the guarantee for postcondition paragaraphs, and then reviews clauses 18-30 to apply that guarantee consistently. We do not want to pick up these issues piecemeal, as we risk openning many issues in an ongoing process.

Proposed resolution:

This wording is relative to N3376.

template <class string_traits, class A>
  basic_regex& assign(const basic_string<charT, string_traits, A>& s,
    flag_type f = regex_constants::ECMAScript);

[…]

-15- Effects: Assigns the regular expression contained in the string s, interpreted according the flags specified in f. If an exception is thrown, *this is unchanged.

-16- Postconditions: If no exception is thrown, flags() returns f and mark_count() returns the number of marked sub-expressions within the expression.


2139. What is a user-defined type?

Section: 17.6.4.2.1 [namespace.std], 19.5 [syserr], 20.7.7.1 [allocator.uses.trait], 20.9.9.1.1 [func.bind.isbind], 20.9.9.1.2 [func.bind.isplace], 20.9.12 [unord.hash], 20.10.7.6 [meta.trans.other], 22.3.1 [locale], 22.4.1.4 [locale.codecvt], 28.12.1.4 [re.regiter.incr] Status: Deferred Submitter: Loïc Joly Opened: 2012-03-08 Last modified: 2012-11-14

View other active issues in [namespace.std].

View all other issues in [namespace.std].

View all issues with Deferred status.

Discussion:

The expression "user-defined type" is used in several places in the standard, but I'm not sure what it means. More specifically, is a type defined in the standard library a user-defined type?

From my understanding of English, it is not. From most of the uses of this term in the standard, it seem to be considered as user defined. In some places, I'm hesitant, e.g. 17.6.4.2.1 [namespace.std] p1:

A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.

Does it mean we are allowed to add in the namespace std a specialization for std::vector<std::pair<T, U>>, for instance?

Additional remarks from the reflector discussion: The traditional meaning of user-defined types refers to class types and enum types, but the library actually means here user-defined types that are not (purely) library-provided. Presumably a new term - like user-provided type - should be introduced and properly defined.

[ 2012-10 Portland: Move to Deferred ]

The issue is real, in that we never define this term and rely on a "know it when I see it" intuition. However, there is a fear that any attempt to pin down a definition is more likely to introduce bugs than solve them - getting the wording for this precisely correct is likely far more work than we are able to give it.

There is unease at simple closing as NAD, but not real enthusiasm to provide wording either. Move to Deferred as we are not opposed to some motivated individual coming back with full wording to review, but do not want to go out of our way to encourage someone to work on this in preference to other issues.

Proposed resolution:


2142. packaged_task::operator() synchronization too broad?

Section: 30.6.9.1 [futures.task.members] Status: Ready Submitter: Pete Becker Opened: 2012-03-12 Last modified: 2013-10-15

View all other issues in [futures.task.members].

View all issues with Ready status.

Discussion:

According to 30.6.9.1 [futures.task.members] p.18:

[A] successful call to [packaged_task::]operator() synchronizes with a call to any member function of a future or shared_future object that shares the shared state of *this.

This requires that the call to operator() synchronizes with calls to future::wait_for, future::wait_until, shared_future::wait_for, and shared_future::wait_until, even when these functions return because of a timeout.

[2012, Portland: move to Open]

If it said "a successful return from" (or "a return from" to cover exceptions) the problem would be more obvious.

Detlef: will ask Anthony Williams to draft some wording.

Moved to open (Anthony drafted to draft)

[2013-09, Chicago: move to Ready]

Anthony's conclusion is that the offending paragraph is not needed. Already included in the statement that the state is made ready.

Recommendation: Remove 30.6.9.1 [futures.task.members] p18 (the synchronization clause). Redundant because of 30.6.4 [futures.state] p9.

Moved to Ready

Proposed resolution:

This wording is relative to N3691.

  1. Remove 30.6.9.1 [futures.task.members] p18 as indicated:

    void operator()(ArgTypes... args);
    

    […]

    -18- Synchronization: a successful call to operator() synchronizes with (1.10) a call to any member function of a future or shared_future object that shares the shared state of *this. The completion of the invocation of the stored task and the storage of the result (whether normal or exceptional) into the shared state synchronizes with (1.10) the successful return from any member function that detects that the state is set to ready. [Note: operator() synchronizes and serializes with other functions through the shared state. — end note]


2146. Are reference types Copy/Move-Constructible/Assignable or Destructible?

Section: 17.6.3.1 [utility.arg.requirements] Status: Open Submitter: Nikolay Ivchenkov Opened: 2012-03-23 Last modified: 2013-10-15

View other active issues in [utility.arg.requirements].

View all other issues in [utility.arg.requirements].

View all issues with Open status.

Discussion:

According to 17.6.3.1 [utility.arg.requirements] p1

The template definitions in the C++ standard library refer to various named requirements whose details are set out in tables 17–24. In these tables, T is an object or reference type to be supplied by a C++ program instantiating a template; a, b, and c are values of type (possibly const) T; s and t are modifiable lvalues of type T; u denotes an identifier; rv is an rvalue of type T; and v is an lvalue of type (possibly const) T or an rvalue of type const T.

Is it really intended that T may be a reference type? If so, what should a, b, c, s, t, u, rv, and v mean? For example, are "int &" and "int &&" MoveConstructible?

As far as I understand, we can explicitly specify template arguments for std::swap and std::for_each. Can we use reference types there?

  1. #include <iostream>
    #include <utility>
    
    int main()
    {
      int x = 1;
      int y = 2;
      std::swap<int &&>(x, y); // undefined?
      std::cout << x << " " << y << std::endl;
    }
    
  2. #include <algorithm>
    #include <iostream>
    #include <iterator>
    #include <utility>
    
    struct F
    {
      void operator()(int n)
      {
        std::cout << n << std::endl;
        ++count;
      }
      int count;
    } f;
    
    int main()
    {
      int arr[] = { 1, 2, 3 };
      auto&& result = std::for_each<int *, F &&>( // undefined?
        std::begin(arr),
        std::end(arr),
        std::move(f));
      std::cout << "count: " << result.count << std::endl;
    }
    

Are these forms of usage well-defined?

Let's also consider the following constructor of std::thread:

template <class F, class ...Args>
explicit thread(F&& f, Args&&... args);

Requires: F and each Ti in Args shall satisfy the MoveConstructible requirements.

When the first argument of this constructor is an lvalue (e.g. a name of a global function), template argument for F is deduced to be lvalue reference type. What should "MoveConstructible" mean with regard to an lvalue reference type? Maybe the wording should say that std::decay<F>::type and each std::decay<Ti>::type (where Ti is an arbitrary item in Args) shall satisfy the MoveConstructible requirements?

[2013-03-15 Issues Teleconference]

Moved to Open.

The questions raised by the issue are real, and should have a clear answer.

Proposed resolution:


2151. basic_string<>::swap semantics ignore allocators

Section: 21.4.1 [string.require] Status: Open Submitter: Robert Shearer Opened: 2012-04-13 Last modified: 2013-10-15

View other active issues in [string.require].

View all other issues in [string.require].

View all issues with Open status.

Discussion:

In C++11, basic_string is not described as a "container", and is not governed by the allocator-aware container semantics described in sub-clause 23.2 [container.requirements]; as a result, and requirements or contracts for the basic_string interface must be documented in Clause 21 [strings].

Sub-clause 21.4.6.8 [string::swap] defines the swap member function with no requirements, and with guarantees to execute in constant time without throwing. Fulfilling such a contract is not reasonable in the presence of unequal non-propagating allocators.

In contrast, 23.2.1 [container.requirements.general] p7 declares the behavior of member swap for containers with unequal non-propagating allocators to be undefined.

Resolution proposal:

Additional language from Clause 23 [containers] should probably be copied to Clause 21 [strings]. I will refrain from an exactly recommendation, however, as I am raising further issues related to the language in Clause 23 [containers].

[2013-03-15 Issues Teleconference]

Moved to Open.

Alisdair has offered to provide wording.

Telecon notes that 23.2.1 [container.requirements.general]p13 says that string is an allocator-aware container.

Proposed resolution:


2152. Instances of standard container types are not swappable

Section: 17.6.3.2 [swappable.requirements], 23.2.1 [container.requirements.general] Status: Open Submitter: Robert Shearer Opened: 2012-04-13 Last modified: 2013-10-15

View all other issues in [swappable.requirements].

View all issues with Open status.

Discussion:

Sub-clause 17.6.3.2 [swappable.requirements] defines two notions of swappability: a binary version defining when two objects are swappable with one another, and a unary notion defining whether an object is swappable (without qualification), with the latter definition requiring that the object satisfy the former with respect to all values of the same type.

Let T be a container type based on a non-propagating allocator whose instances do not necessarily compare equal. Then sub-clause 23.2.1 [container.requirements.general] p7 implies that no object t of type T is swappable (by the unary definition).

Throughout the standard it is the unary definition of "swappable" that is listed as a requirement (with the exceptions of 20.2.2 [utility.swap] p4, 20.3.2 [pairs.pair] p31, 20.4.2.3 [tuple.swap] p2, 25.3.3 [alg.swap] p2, and 25.3.3 [alg.swap] p6, which use the binary definition). This renders many of the mutating sequence algorithms of sub-clause 25.3 [alg.modifying.operations], for example, inapplicable to sequences of standard container types, even where every element of the sequence is swappable with every other.

Note that this concern extends beyond standard containers to all future allocator-based types.

Resolution proposal:

I see two distinct straightforward solutions:

  1. Modify the requirements of algorithms from sub-clause 25.3 [alg.modifying.operations], and all other places that reference the unary "swappable" definition, to instead use the binary "swappable with" definition (over a domain appropriate to the context). The unary definition of "swappable" could then be removed from the standard.
  2. Modify sub-clause 23.2.1 [container.requirements.general] such that objects of standard container types are "swappable" by the unary definition.

I favor the latter solution, for reasons detailed in the following issue.

[ 2012-10 Portland: Move to Open ]

The issue is broader than containers with stateful allocotors, although they are the most obvious example contained within the standard itself. The basic problem is that once you have a stateful allocator, that does not propagate_on_swap, then whether two objects of this type can be swapped with well defined behavior is a run-time property (the allocators compare equal) rather than a simple compile-time property that can be deduced from the type. Strictly speaking, any type where the nature of swap is a runtime property does not meet the swappable requirements of C++11, although typical sequences of such types are going to have elements that are all swappable with any other element in the sequence (using our other term of art for specifying requirements) as the common case is a container of elements who all share the same allocator.

The heart of the problem is that the swappable requirments demand that any two objects of the same type be swappable with each other, so if any two such objects would not be swappable with each other, then the whole type is never swappable. Many algorithms in clause 25 are specified in terms of swappable which is essentially an overspecification as all they actually need is that any element in the sequence is swappable with any other element in the sequence.

At this point Howard joins the discussion and points out that the intent of introducing the two swap-related terms was to support vector<bool>::reference types, and we are reading something into the wording that was never intended. Consuses is that regardless of the intent, that is what the words today say.

There is some support to see a paper reviewing the whole of clause 25 for this issue, and other select clauses as may be necessary.

There was some consideration to introducing a note into the front of clause 25 to indicate swappable requirements in the clause should be interpreted to allow such awkward types, but ultimately no real enthusiasm for introducing a swappable for clause 25 requirement term, especially if it confusingly had the same name as a term used with a subtly different meaning through the rest of the standard.

There was no enthusiasm for the alternate resolution of requiring containers with unequal allocators that do not propagate provide a well-defined swap behavior, as it is not believed to be possible without giving swap linear complexity for such values, and even then would require adding the constraint that the container element types are CopyConstructible.

Final conclusion: move to open pending a paper from a party with a strong interest in stateful allocators.

Proposed resolution:


2153. Narrowing of the non-member swap contract

Section: 20.2.2 [utility.swap], 17.6.3.2 [swappable.requirements], 23.2.1 [container.requirements.general] Status: Open Submitter: Robert Shearer Opened: 2012-04-13 Last modified: 2013-10-15

View all issues with Open status.

Discussion:

Sub-clause 20.2.2 [utility.swap] defines a non-member 'swap' function with defined behavior for all MoveConstructible and MoveAssignable types. It does not guarantee constant-time complexity or noexcept in general, however this definition does render all objects of MoveConstructible and MoveAssignable type swappable (by the unary definition of sub-clause 17.6.3.2 [swappable.requirements]) in the absence of specializations or overloads.

The overload of the non-member swap function defined in Table 96, however, defines semantics incompatible with the generic non-member swap function, since it is defined to call a member swap function whose semantics are undefined for some values of MoveConstructible and MoveAssignable types.

The obvious (perhaps naive) interpretation of sub-clause 17.6.3.2 [swappable.requirements] is as a guide to the "right" semantics to provide for a non-member swap function (called in the context defined by 17.6.3.2 [swappable.requirements] p3) in order to provide interoperable user-defined types for generic programming. The standard container types don't follow these guidelines.

More generally, the design in the standard represents a classic example of "contract narrowing". It is entirely reasonable for the contract of a particular swap overload to provide more guarantees, such as constant-time execution and noexcept, than are provided by the swap that is provided for any MoveConstructible and MoveAssignable types, but it is not reasonable for such an overload to fail to live up to the guarantees it provides for general types when it is applied to more specific types. Such an overload or specialization in generic programming is akin to an override of an inherited virtual function in OO programming: violating a superclass contract in a subclass may be legal from the point of view of the language, but it is poor design and can easily lead to errors. While we cannot prevent user code from providing overloads that violate the more general swap contract, we can avoid doing so within the library itself.

My proposed resolution is to draw a sharp distinction between member swap functions, which provide optimal performance but idiosyncratic contracts, and non-member swap functions, which should always fulfill at least the contract of 20.2.2 [utility.swap] and thus render objects swappable. The member swap for containers with non-propagating allocators, for example, would offer constant-time guarantees and noexcept but would only offer defined behavior for values with allocators that compare equal; non-member swap would test allocator equality and then dispatch to either member swap or std::swap depending on the result, providing defined behavior for all values (and rendering the type "swappable"), but offering neither the constant-time nor the noexcept guarantees.

[2013-03-15 Issues Teleconference]

Moved to Open.

This topic deserves more attention than can be given in the telocon, and there is no proposed resolution.

Proposed resolution:


2154. What exactly does compile-time complexity imply?

Section: 26.5.1.3 [rand.req.urng] Status: New Submitter: John Salmon Opened: 2012-04-26 Last modified: 2012-11-14

View other active issues in [rand.req.urng].

View all other issues in [rand.req.urng].

View all issues with New status.

Discussion:

The expressions G::min() and G::max() in Table 116 in 26.5.1.3 [rand.req.urng] are specified as having "compile-time" complexity.

It is not clear what, exactly, this requirement implies. If a URNG has a method:

static int min();

then is the method required to have a constexpr qualifier? I believe the standard would benefit from clarification of this point.

Proposed resolution:


2155. Macro __bool_true_false_are_defined should be removed

Section: 18.10 [support.runtime] Status: Open Submitter: Thomas Plum Opened: 2012-04-30 Last modified: 2013-10-15

View other active issues in [support.runtime].

View all other issues in [support.runtime].

View all issues with Open status.

Discussion:

Since C99, the C standard describes a macro named __bool_true_false_are_defined.

In the process of harmonizing C++11 with C99, this name became part of the C++ standard.

I propose that all mention of this name should be removed from the C and C++ standards.

Here's the problem: The name was originally proposed as a transition tool, so that the headers for a project could contain lines like the following.

#if !defined(__bool_true_false_are_defined)
#define bool int /* or whatever */
#define true 1
#define false 0
#endif

Then when the project was compiled by a "new" compiler that implemented bool as defined by the evolving C++98 or C99 standards, those lines would be skipped; but when compiled by an "old" compiler that didn't yet provide bool, true, and false, then the #define's would provide a simulation that worked for most purposes.

It turns out that there is an unfortunate ambiguity in the name. One interpretation is as shown above, but a different reading says "bool, true, and false are #define'd", i.e. that the meaning of the macro is to assert that these names are macros (not built-in) ... which is true in C, but not in C++.

In C++11, the name appears in parentheses followed by a stray period, so some editorial change is needed in any event:

18.10 [support.runtime] para 1:

Headers <csetjmp> (nonlocal jumps), <csignal> (signal handling), <cstdalign> (alignment), <cstdarg> (variable arguments), <cstdbool> (__bool_true_false_are_defined). <cstdlib> (runtime environment getenv(), system()), and <ctime> (system clock clock(), time()) provide further compatibility with C code.

However, para 2 says

"The contents of these headers are the same as the Standard C library headers <setjmp.h>, <signal.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stdlib.h>, and <time.h>, respectively, with the following changes:",

and para 8 says

"The header <cstdbool> and the header <stdbool.h> shall not define macros named bool, true, or false."

Thus para 8 doesn't exempt the C++ implementation from the arguably clear requirement of the C standard, to provide a macro named __bool_true_false_are_defined defined to be 1.

Real implementations of the C++ library differ, so the user cannot count upon any consistency; furthermore, the usefulness of the transition tool has faded long ago.

That's why my suggestion is that both C and C++ standards should eliminate any mention of __bool_true_false_are_defined. In that case, the name belongs to implementers to provide, or not, as they choose.

[2013-03-15 Issues Teleconference]

Moved to Open.

While not strictly necessary, the clean-up look good.

We would like to hear from our C liaison before moving on this issue though.

Proposed resolution:


2156. Unordered containers' reserve(n) reserves for n-1 elements

Section: 23.2.5 [unord.req] Status: Open Submitter: Daniel James Opened: 2012-05-07 Last modified: 2013-10-15

View other active issues in [unord.req].

View all other issues in [unord.req].

View all issues with Open status.

Discussion:

I think that unordered containers' reserve doesn't quite do what it should. I'd expect after calling x.reserve(n) to be able to insert n elements without invalidating iterators. But as the standard is written (I'm looking at n3376), I think the guarantee only holds for n-1 elements.

For a container with max_load_factor of 1, reserve(n) is equivalent to rehash(ceil(n/1)), ie. rehash(n). rehash(n) requires that the bucket count is >= n, so it can be n (Table 103). The rule is that insert shall not affect the validity of iterators if (N + n) < z * B (23.2.5 [unord.req] p15). But for this case the two sides of the equation are equal, so insert can affect the validity of iterators.

[2013-03-16 Howard comments and provides wording]

Given the following:

LF := load_factor()
MLF := max_load_factor()
S := size()
B := bucket_count()

LF == S/B

The container has an invariant:

LF <= MLF

Therefore:

MLF >= S/B
S <= MLF * B
B >= S/MLF

[2013-03-15 Issues Teleconference]

Moved to Open.

Howard to provide rationale and potentally revised wording.

Proposed resolution:

This wording is relative to N3485.

  1. In 23.2.5 [unord.req] Table 103 — Unordered associative container requirements, change the post-condition in the row for a.rehash(n) to:

    Post: a.bucket_count() >= a.size() / a.max_load_factor() and a.bucket_count() >= n.
  2. In 23.2.5 [unord.req]/p15 change

    The insert and emplace members shall not affect the validity of iterators if (N+n) <= z * B, where N is the number of elements in the container prior to the insert operation, n is the number of elements inserted, B is the container’s bucket count, and z is the container’s maximum load factor.

2157. How does std::array<T,0> initialization work when T is not default-constructible?

Section: 23.3.2.8 [array.zero] Status: Open Submitter: Daryle Walker Opened: 2012-05-08 Last modified: 2012-11-14

View all other issues in [array.zero].

View all issues with Open status.

Discussion:

Objects of std::array<T,N> are supposed to be initialized with aggregate initialization (when not the destination of a copy or move). This clearly works when N is positive. What happens when N is zero? To continue using an (inner) set of braces for initialization, a std::array<T,0> implementation must have an array member of at least one element, and let default initialization take care of those secret elements. This cannot work when T has a set of constructors and the default constructor is deleted from that set. Solution: Add a new paragraph in 23.3.2.8 [array.zero]:

The unspecified internal structure of array for this case shall allow initializations like:

array<T, 0> a = { };

and said initializations must be valid even when T is not default-constructible.

[2012, Portland: Move to Open]

Some discussion to understand the issue, which is that implementations currently have freedom to implement an empty array by holding a dummy element, and so might not support value initialization, which is surprising when trying to construct an empty container. However, this is not mandated, it is an unspecified implementation detail.

Jeffrey points out that the implication of 23.3.2.1 [array.overview] is that this initialization syntax must be supported by empty array objects already. This is a surprising inference that was not obvious to the room, but consensus is that the reading is accurate, so the proposed resolution is not necessary, although the increased clarity may be useful.

Further observation is that the same clause effectively implies that T must always be DefaultConstructible, regardless of N for the same reasons - as an initializer-list may not supply enough values, and the remaining elements must all be value initialized.

Concern that we are dancing angels on the head of pin, and that relying on such subtle implications in wording is not helpful. We need a clarification of the text in this area, and await wording.

Proposed resolution:

This wording is relative to N3376.

Add the following new paragraph between the current 23.3.2.8 [array.zero] p1 and p2:

-1- array shall provide support for the special case N == 0.

-?- The unspecified internal structure of array for this case shall allow initializations like:

array<T, 0> a = { };

and said initializations must be valid even when T is not default-constructible.

-2- In the case that N == 0, begin() == end() == unique value. The return value of data() is unspecified.

-3- The effect of calling front() or back() for a zero-sized array is undefined.

-4- Member function swap() shall have a noexcept-specification which is equivalent to noexcept(true).


2158. Conditional copy/move in std::vector

Section: 23.3.6.3 [vector.capacity] Status: New Submitter: Nikolay Ivchenkov Opened: 2012-05-08 Last modified: 2012-11-14

View other active issues in [vector.capacity].

View all other issues in [vector.capacity].

View all issues with New status.

Discussion:

There are various operations on std::vector that can cause elements of the vector to be moved from one location to another. A move operation can use either rvalue or const lvalue as argument; the choice depends on the value of !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, where T is the element type. Thus, some operations on std::vector (e.g. 'resize' with single parameter, 'reserve', 'emplace_back') should have conditional requirements. For example, let's consider the requirement for 'reserve' in N3376 – 23.3.6.3 [vector.capacity]/2:

Requires: T shall be MoveInsertable into *this.

This requirement is not sufficient if an implementation is free to select copy constructor when !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value evaluates to true. Unfortunately, is_copy_constructible cannot reliably determine whether T is really copy-constructible. A class may contain public non-deleted copy constructor whose definition does not exist or cannot be instantiated successfully (e.g., std::vector<std::unique_ptr<int>> has copy constructor, but this type is not copy-constructible). Thus, the actual requirements should be:

Maybe it would be useful to introduce a new name for such conditional requirement (in addition to "CopyInsertable" and "MoveInsertable").

Proposed resolution:


2160. Unintended destruction ordering-specification of resize

Section: 23.3.6.3 [vector.capacity] Status: Open Submitter: Daniel Krügler Opened: 2012-06-07 Last modified: 2013-10-15

View other active issues in [vector.capacity].

View all other issues in [vector.capacity].

View all issues with Open status.

Discussion:

As part of resolving LWG issue 2033 a wording change was done for resize() to respect the problem mentioned in the question:

Does a call to 'void resize(size_type sz)' of std::vector require the element type to be MoveAssignable because the call erase(begin() + sz, end()) mentioned in the Effects paragraph would require the element type to be MoveAssignable?

The wording change was to replace in 23.3.3.3 [deque.capacity] and 23.3.6.3 [vector.capacity]:

-1- Effects: If sz <= size(), equivalent to erase(begin() + sz, end()); […]

by:

-1- Effects: If sz <= size(), equivalent to calling pop_back() size() - sz times. […]

The overlooked side-effect of this wording change is that this implies a destruction order of the removed elements to be in reverse order of construction, but the previous version did not impose any specific destruction order due to the way how the semantics of erase is specified in Table 100.

Given the program:

#include <vector>
#include <iostream>

struct Probe {
  int value;
  Probe() : value(0) {}
  Probe(int value) : value(value) {}
  ~Probe() { std::cout << "~Probe() of " << value << std::endl; }
};

int main() {
  std::vector<Probe> v;
  v.push_back(Probe(1));
  v.push_back(Probe(2));
  v.push_back(Probe(3));
  std::cout << "---" << std::endl;
  v.resize(0);
}

the last three lines of the output for every compiler I tested was:

~Probe() of 1
~Probe() of 2
~Probe() of 3

but a conforming implementation would now need to change this order to

~Probe() of 3
~Probe() of 2
~Probe() of 1

This possible stringent interpretation makes sense, because one can argue that sequence containers (or at least std::vector) should have the same required destruction order of it's elements, as elements of a C array or controlled by memory deallocated with an array delete have. I also learned that libc++ does indeed implement std::vector::resize in a way that the second output form is observed.

While I agree that required reverse-destruction would better mimic the natural behaviour of std::vector this was not required in C++03 and this request may be too strong. My current suggestion would be to restore the effects of the previous wording in regard to the destruction order, because otherwise several currently existing implementations would be broken just because of this additional requirement.

[2013-03-15 Issues Teleconference]

Moved to Open.

Jonathan says that he believes this is a valid issue.

Walter wonders if this was intended when we made the previous change - if so, this would be NAD.

Jonathan said that Issue 2033 doesn't mention ordering.

Walter then asked if anyone is really unhappy that we're destroying items in reverse order of construction.

Jonathan points out that this conflicts with existing practice (libstc++, but not libc++).

Jonathan asked for clarification as to whether this change was intended by 2033.

Proposed resolution:


2161. const equivalence of std::map

Section: 23.4 [associative], 23.5 [unord] Status: New Submitter: Bjarne Stroustrup Opened: 2012-06-18 Last modified: 2013-10-15

View all other issues in [associative].

View all issues with New status.

Discussion:

As described in the reflector discussion c++std-core-21860 consider the following example:

map<const int, int> mci{};
map<int, int> mi = mci; // ??
mci[1] = 2;
mi[1] = 2;

Should it be required that the marked initialization is well-formed? As a possible solution this could be realized by an alias template:

template <class K, class T>
struct OriginalMap { […] };

template <class K, class T>
using ImprovedMap = OriginalMap<const K, T>;

Proposed resolution:


2164. What are the semantics of vector.emplace(vector.begin(), vector.back())?

Section: 23.3.6.5 [vector.modifiers], 23.2 [container.requirements] Status: New Submitter: Howard Hinnant Opened: 2012-07-07 Last modified: 2012-11-14

View other active issues in [vector.modifiers].

View all other issues in [vector.modifiers].

View all issues with New status.

Discussion:

Nikolay Ivchenkov recently brought the following example on the std-discussion newsgroup, asking whether the following program well-defined:

#include <iostream>
#include <vector>

int main()
{
  std::vector<int> v;
  v.reserve(4);
  v = { 1, 2, 3 };
  v.emplace(v.begin(), v.back());
  for (int x : v)
    std::cout << x << std::endl;
}

Nikolay Ivchenkov:

I think that an implementation of vector's 'emplace' should initialize an intermediate object with v.back() before any shifts take place, then perform all necessary shifts and finally replace the value pointed to by v.begin() with the value of the intermediate object. So, I would expect the following output:

3
1
2
3

GNU C++ 4.7.1 and GNU C++ 4.8.0 produce other results:

2
1
2
3

Howard Hinnant:

I believe Nikolay is correct that vector should initialize an intermediate object with v.back() before any shifts take place. As Nikolay pointed out in another email, this appears to be the only way to satisfy the strong exception guarantee when an exception is not thrown by T's copy constructor, move constructor, copy assignment operator, or move assignment operator as specified by 23.3.6.5 [vector.modifiers]/p1. I.e. if the emplace construction throws, the vector must remain unaltered.

That leads to an implementation that tolerates objects bound to the function parameter pack of the emplace member function may be elements or sub-objects of elements of the container.

My position is that the standard is correct as written, but needs a clarification in this area. Self-referencing emplace should be legal and give the result Nikolay expects. The proposed resolution of LWG 760 is not correct.

Proposed resolution:


2165. std::atomic<X> requires X to be nothrow default constructible

Section: 29.5 [atomics.types.generic], 29.6 [atomics.types.operations] Status: Core Submitter: Jonathan Wakely Opened: 2012-07-19 Last modified: 2013-10-15

View all other issues in [atomics.types.generic].

Discussion:

As raised in c++std-lib-32781, this fails to compile even though the default constructor is not used:

#include <atomic>

struct X {
  X() noexcept(false) {}
  X(int) { }
};

std::atomic<X> x(3);

This is because atomic<T>'s default constructor is declared to be non-throwing and is explicitly-defaulted on its first declaration:

atomic() noexcept = default;

This is ill-formed if the implicitly-declared default constructor would not be non-throwing.

Possible solutions:

  1. Add nothrow default constructible to requirements for template argument of the generic atomic<T>
  2. Remove atomic<T>::atomic() from the overload set if T is not nothrow default constructible.
  3. Remove noexcept from atomic<T>::atomic(), allowing it to be deduced (but the default constructor is intended to be always noexcept)
  4. Do not default atomic<T>::atomic() on its first declaration (but makes the default constructor user-provided and so prevents atomic<T> being trivial)
  5. A core change to allow the mismatched exception specification if the default constructor isn't used (see c++std-core-21990)

[2012, Portland: move to Core]

Recommend referring to core to see if the constructor noexcept mismatch can be resolved there. The issue is not specific to concurrency.

Proposed resolution:


2166. Heap property underspecified?

Section: 25.4.6 [alg.heap.operations] Status: New Submitter: Peter Sommerlad Opened: 2012-07-09 Last modified: 2012-11-14

View all other issues in [alg.heap.operations].

View all issues with New status.

Discussion:

Another similar issue to the operator< vs greater in nth_element but not as direct occurs in 25.4.6 [alg.heap.operations]:

-1- A heap is a particular organization of elements in a range between two random access iterators [a,b). Its two key properties are:

  1. There is no element greater than *a in the range and
  2. *a may be removed by pop_heap(), or a new element added by push_heap(), in O(log(N)) time.

As noted by Richard Smith, it seems that the first bullet should read:

*a is not less than any element in the range

Even better the heap condition could be stated here directly, instead of leaving it unspecified, i.e.,

Each element at (a+2*i+1) and (a+2*i+2) is less than the element at (a+i), if those elements exist, for i>=0.

But may be that was may be intentional to allow other heap organizations?

See also follow-up discussion of c++std-lib-32780.

Proposed resolution:


2168. Inconsistent specification of uniform_real_distribution constructor

Section: 26.5.8.2.2 [rand.dist.uni.real] Status: New Submitter: Marshall Clow Opened: 2012-07-14 Last modified: 2012-11-14

View all issues with New status.

Discussion:

uniform_real says in 26.5.8.2.2 [rand.dist.uni.real] p1:

A uniform_real_distribution random number distribution produces random numbers x, a ≤ x < b,

but also that (26.5.8.2.2 [rand.dist.uni.real] p2):

explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);

-2- Requires: a ≤ b and b - a ≤ numeric_limits<RealType>::max().

If you construct a uniform_real_distribution<RealType>(a, b) where there are no representable numbers between 'a' and 'b' (using RealType's representation) then you cannot satisfy 26.5.8.2.2 [rand.dist.uni.real].

An obvious example is when a == b.

Proposed resolution:


2170. Aggregates cannot be DefaultConstructible

Section: 17.6.3.1 [utility.arg.requirements] Status: Review Submitter: Daniel Krügler Opened: 2012-07-19 Last modified: 2013-10-15

View other active issues in [utility.arg.requirements].

View all other issues in [utility.arg.requirements].

View all issues with Review status.

Discussion:

The lack of the definition of the DefaultConstructible requirements in C++03 was fixed by LWG 724 at a time where the core rules of list-initialization were slightly different than today, at that time value-initialization (shortly) was the primary rule for class types, i.e. just before applying CWG 1301, CWG 1324, and CWG 1368.

The order in 8.5.4 [dcl.init.list] p3 was changed to respect aggregate initialization, but that had the side-effect that formally aggregate types cannot satisfy the DefaultConstructible requirements anymore, because we require that

T u{};

value-initializes the object u.

Of-course exclusion of aggregates was not intended, therefore I suggest to extend the requirements in Table 19 (17.6.3.1 [utility.arg.requirements]) for empty aggregate-initialization as well.

[ 2012-10 Portland: Move to Core ]

We are not qualified to pick apart the Core rules quickly at this point, but the consensus is that if the core language has changed in this manner, then the fix should similarly be applied in Core - this is not something that we want users of the language to have to say every time they want to Value initialize (or aggregate initialize) an object.

More to Open until we get a clear response from Core, Alisdair to file an issue with Mike.

[2013-04 Bristol: Back to Library]

The Core Working group opened, discussed, and resolved CWG 1578 as NAD for this library-related problem: Empty aggregate initialization and value-initialization are different core language concepts, and this difference can be observed (e.g. for a type with a deleted default-constructor).

Proposed resolution:

This wording is relative to N3691.

Change Table 19 in 17.6.3.1 [utility.arg.requirements] as indicated:

Table 19 — DefaultConstructible requirements [defaultconstructible]
Expression Post-condition
T t; object t is default-initialized
T u{}; object u is value-initialized or aggregate-initialized
T()
T{}
a temporary object of type T is value-initialized or aggregate-initialized

2173. The meaning of operator + in the description of the algorithms

Section: 25 [algorithms] Status: New Submitter: Nikolay Ivchenkov Opened: 2012-08-01 Last modified: 2012-11-14

View all other issues in [algorithms].

View all issues with New status.

Discussion:

According to 25.1 [algorithms.general]/12,

In the description of the algorithms operators + and - are used for some of the iterator categories for which they do not have to be defined. In these cases the semantics of a+n is the same as that of

X tmp = a;
advance(tmp, n);
return tmp;

There are several places where such operator + is applied to an output iterator — for example, see the description of std::copy:

template<class InputIterator, class OutputIterator>
OutputIterator copy(InputIterator first, InputIterator last,
                    OutputIterator result);

-1- Effects: Copies elements in the range [first,last) into the range [result,result + (last - first)) starting from first and proceeding to last. For each non-negative integer n < (last - first), performs *(result + n) = *(first + n).

std::advance is not supposed to be applicable to output iterators, so we need a different method of description.

See also message c++std-lib-32908.

Proposed resolution:


2178. Allocator requirement changes not mentioned Annex C

Section: 17.6.3.5 [allocator.requirements], C.4 [diff.library] Status: Open Submitter: Nevin Liber Opened: 2012-08-14 Last modified: 2012-11-14

View other active issues in [allocator.requirements].

View all other issues in [allocator.requirements].

View all issues with Open status.

Discussion:

Given that a number of things were removed from the allocator requirements (reference, const_reference, address() in 17.6.3.5 [allocator.requirements]), it seems that these incompatible changes should be mentioned in Annex C.4 [diff.library], more specifically in [diff.cpp03].

[ 2012-10 Portland: Move to Open ]

It was clearly pointed out by Bill during the C++11 process that our change to allocator requirements potentially broke 3rd party user containers written to expect C++03 allocators, or rather, an allocator written to the minimal requirements of C++11 might not be guaranteed to work with a container written to the previous rules. This was a trade-off in making allocaters easier to write by use of the allocator_traits framework.

This probably does merit a write-up in Annex C, and we look forward to seeing wording. Until then, the best we can do is move the issue to Open.

Proposed resolution:


2179. enable_shared_from_this and construction from raw pointers

Section: 20.8.2.4 [util.smartptr.enab], 20.8.2.2.1 [util.smartptr.shared.const] Status: Open Submitter: Daniel Krügler Opened: 2012-08-16 Last modified: 2013-10-15

View all issues with Open status.

Discussion:

On reflector message c++std-lib-32927, Matt Austern asked whether the following example should be well-defined or not

struct X : public enable_shared_from_this<X> { };
auto xraw = new X;
shared_ptr<X> xp1(xraw);
shared_ptr<X> xp2(xraw);

pointing out that 20.8.2.2.1 [util.smartptr.shared.const] does not seem to allow it, since xp1 and xp2 aren't allowed to share ownership, because each of them is required to have use_count() == 1. Despite this wording it might be reasonable (and technical possible) to implement that request.

On the other hand, there is the non-normative note in 20.8.2.4 [util.smartptr.enab] p11 (already part of TR1):

The shared_ptr constructors that create unique pointers can detect the presence of an enable_shared_from_this base and assign the newly created shared_ptr to its __weak_this member.

Now according to the specification in 20.8.2.2.1 [util.smartptr.shared.const] p3-7:

template<class Y> explicit shared_ptr(Y* p);

the notion of creating unique pointers can be read to be included by this note, because the post-condition of this constructor is unique() == true. Evidence for this interpretation seems to be weak, though.

Howard Hinnant presented the counter argument, that actually the following is an "anti-idiom" and it seems questionable to teach it to be well-defined in any case:

auto xraw = new X;
shared_ptr<X> xp1(xraw);
shared_ptr<X> xp2(xraw);

He also pointed out that the current post-conditions of the affected shared_ptr constructor would need to be reworded.

It needs to be decided, which direction to follow. If this idiom seems too much broken to be supported, the note could be improved. If it should be supported, the constructors in 20.8.2.2.1 [util.smartptr.shared.const] need a careful analysis to ensure that post-conditions are correct.

Several library implementations currently do not support this example, instead they typically cause a crash. Matt points out that there are currently no explicit requirements imposed on shared_ptr objects to prevent them from owning the same underlying object without sharing the ownership. It might be useful to add such a requirement.

[2013-03-15 Issues Teleconference]

Moved to Open.

More discussion is needed to pick a direction to guide a proposed resolution.

[2013-05-09 Jonathan comments]

The note says the newly created shared_ptr is assigned to the weak_ptr member. It doesn't say before doing that the shared_ptr should check if the weak_ptr is non-empty and possibly share ownership with some other pre-existing shared_ptr.

Proposed resolution:


2181. Exceptions from seed sequence operations

Section: 26.5.1.2 [rand.req.seedseq], 26.5.3 [rand.eng], 26.5.4 [rand.adapt] Status: Open Submitter: Daniel Krügler Opened: 2012-08-18 Last modified: 2013-10-15

View all other issues in [rand.req.seedseq].

View all issues with Open status.

Discussion:

LWG issue 2180 points out some deficiences in regard to the specification of the library-provided type std::seed_seq regarding exceptions, but there is another specification problem in regard to general types satisfying the seed sequence constraints (named SSeq) as described in 26.5.1.2 [rand.req.seedseq].

26.5.3 [rand.eng] p3 and 26.5.4.1 [rand.adapt.general] p3 say upfront:

Except where specified otherwise, no function described in this section 26.5.3 [rand.eng]/26.5.4 [rand.adapt] throws an exception.

This constraint causes problems, because the described templates in these sub-clauses depend on operations of SSeq::generate() which is a function template, that depends both on operations provided by the implementor of SSeq (e.g. of std::seed_seq), and those of the random access iterator type provided by the caller. With class template linear_congruential_engine we have just one example for a user of SSeq::generate() via:

template<class Sseq> 
linear_congruential_engine<>::linear_congruential_engine(Sseq& q);

template<class Sseq> 
void linear_congruential_engine<>::seed(Sseq& q);

None of these operations has an exclusion rule for exceptions.

As described in 2180 the wording for std::seed_seq should and can be fixed to ensure that operations of seed_seq::generate() won't throw except from operations of the provided iterator range, but there is no corresponding "safety belt" for user-provided SSeq types, since 26.5.1.2 [rand.req.seedseq] does not impose no-throw requirements onto operations of seed sequences.

  1. A quite radical step to fix this problem would be to impose general no-throw requirements on the expression q.generate(rb,re) from Table 115, but this is not as simple as it looks initially, because this function again depends on general types that are mutable random access iterators. Typically, we do not impose no-throw requirements on iterator operations and this would restrict general seed sequences where exceptions are not a problem. Furthermore, we do not impose comparable constraints for other expressions, like that of the expression g() in Table 116 for good reasons, e.g. random_device::operator() explicitly states when it throws exceptions.

  2. A less radical variant of the previous suggestion would be to add a normative requirement on the expression q.generate(rb,re) from Table 115 that says: "Throws nothing if operations of rb and re do not throw exceptions". Nevertheless we typically do not describe conditional Throws elements in proper requirement sets elsewhere (Container requirements excluded, they just describe the containers from Clause 23) and this may exclude resonable implementations of seed sequences that could throw exceptions under rare situations.

  3. The iterator arguments provided to SSeq::generate() for operations in templates of 26.5.3 [rand.eng] and 26.5.4 [rand.adapt] are under control of implementations, so we could impose stricter exceptions requirements on SSeq::generate() for SSeq types that are used to instantiate member templates in 26.5.3 [rand.eng] and 26.5.4 [rand.adapt] solely.

  4. We simply add extra wording to the introductive parts of 26.5.3 [rand.eng] and 26.5.4 [rand.adapt] that specify that operations of the engine (adaptor) templates that depend on a template parameter SSeq throw no exception unless SSeq::generate() throws an exception.

Given these options I would suggest to apply the variant described in the fourth bullet.

The proposed resolution attempts to reduce a lot of the redundancies of requirements in the introductory paragraphs of 26.5.3 [rand.eng] and 26.5.4 [rand.adapt] by introducing a new intermediate sub-clause "Engine and engine adaptor class templates" following sub-clause 26.5.2 [rand.synopsis]. This approach also solves the problem that currently 26.5.3 [rand.eng] also describes requirements that apply for 26.5.4 [rand.adapt] (Constrained templates involving the Sseq parameters).

[2013-04-20, Bristol]

Remove the first bullet point:

?- Throughout this sub-clause general requirements and conventions are described that apply to every class template specified in sub-clause 26.5.3 [rand.eng] and 26.5.4 [rand.adapt]. Phrases of the form "in those sub-clauses" shall be interpreted as equivalent to "in sub-clauses 26.5.3 [rand.eng] and 26.5.4 [rand.adapt]".

Replace "in those sub-clauses" with "in sub-clauses 26.5.3 [rand.eng] and 26.5.4 [rand.adapt]".

Find another place for the wording.

Daniel: These are requirements on the implementation not on the types. I'm not comfortable in moving it to another place without double checking.

Improve the text (there are 4 "for"s): for copy constructors, for copy assignment operators, for streaming operators, and for equality and inequality operators are not shown in the synopses.

Move the information of this paragraph to the paragraphs it refers to:

"-?- Descriptions are provided in those sub-clauses only for engine operations that are not described in 26.5.1.4 [rand.req.eng], for adaptor operations that are not described in 26.5.1.5 [rand.req.adapt], or for operations where there is additional semantic information. In particular, declarations for copy constructors, for copy assignment operators, for streaming operators, and for equality and inequality operators are not shown in the synopses."

Alisdair: I prefer duplication here than consolidation/reference to these paragraphs.

The room showed weakly favjust or for duplication.

Proposed resolution:

This wording is relative to N3376.

  1. Add a new sub-clause titled "Engine and engine adaptor class templates" following sub-clause 26.5.2 [rand.synopsis] (but at the same level) and add one further sub-clause "General" as child of the new sub-clause as follows:

    Engine and engine adaptor class templates [rand.engadapt]

    General [rand.engadapt.general]

    -?- Throughout this sub-clause general requirements and conventions are described that apply to every class template specified in sub-clause 26.5.3 [rand.eng] and 26.5.4 [rand.adapt]. Phrases of the form "in those sub-clauses" shall be interpreted as equivalent to "in sub-clauses 26.5.3 [rand.eng] and 26.5.4 [rand.adapt]".

    -?- Except where specified otherwise, the complexity of each function specified in those sub-clauses is constant.

    -?- Except where specified otherwise, no function described in those sub-clauses throws an exception.

    -?- Every function described in those sub-clauses that has a function parameter q of type SSeq& for a template type parameter named SSeq that is different from type std::seed_seq throws what and when the invocation of q.generate throws.

    -?- Descriptions are provided in those sub-clauses only for engine operations that are not described in 26.5.1.4 [rand.req.eng], for adaptor operations that are not described in 26.5.1.5 [rand.req.adapt], or for operations where there is additional semantic information. In particular, declarations for copy constructors, for copy assignment operators, for streaming operators, and for equality and inequality operators are not shown in the synopses.

    -?- Each template specified in those sub-clauses requires one or more relationships, involving the value(s) of its non-type template parameter(s), to hold. A program instantiating any of these templates is ill-formed if any such required relationship fails to hold.

    -?- For every random number engine and for every random number engine adaptor X defined in those sub-clauses:

    • if the constructor

      template <class Sseq> explicit X(Sseq& q);
      

      is called with a type Sseq that does not qualify as a seed sequence, then this constructor shall not participate in overload resolution;

    • if the member function

      template <class Sseq> void seed(Sseq& q);
      

      is called with a type Sseq that does not qualify as a seed sequence, then this function shall not participate in overload resolution;

    The extent to which an implementation determines that a type cannot be a seed sequence is unspecified, except that as a minimum a type shall not qualify as a seed sequence if it is implicitly convertible to X::result_type.

  2. Edit the contents of sub-clause 26.5.3 [rand.eng] as indicated:

    -1- Each type instantiated from a class template specified in this section 26.5.3 [rand.eng] satisfies the requirements of a random number engine (26.5.1.4 [rand.req.eng]) type and the general implementation requirements specified in sub-clause [rand.engadapt.general].

    -2- Except where specified otherwise, the complexity of each function specified in this section 26.5.3 [rand.eng] is constant.

    -3- Except where specified otherwise, no function described in this section 26.5.3 [rand.eng] throws an exception.

    -4- Descriptions are provided in this section 26.5.3 [rand.eng] only for engine operations that are not described in 26.5.1.4 [rand.req.eng] […]

    -5- Each template specified in this section 26.5.3 [rand.eng] requires one or more relationships, involving the value(s) of its non-type template parameter(s), to hold. […]

    -6- For every random number engine and for every random number engine adaptor X defined in this subclause (26.5.3 [rand.eng]) and in sub-clause 26.5.3 [rand.eng]: […]

  3. Edit the contents of sub-clause 26.5.4.1 [rand.adapt.general] as indicated:

    -1- Each type instantiated from a class template specified in this section 26.5.3 [rand.eng]26.5.4 [rand.adapt] satisfies the requirements of a random number engine adaptor (26.5.1.5 [rand.req.adapt]) type and the general implementation requirements specified in sub-clause [rand.engadapt.general].

    -2- Except where specified otherwise, the complexity of each function specified in this section 26.5.4 [rand.adapt] is constant.

    -3- Except where specified otherwise, no function described in this section 26.5.4 [rand.adapt] throws an exception.

    -4- Descriptions are provided in this section 26.5.4 [rand.adapt] only for engine operations that are not described in 26.5.1.5 [rand.req.adapt] […]

    -5- Each template specified in this section 26.5.4 [rand.adapt] requires one or more relationships, involving the value(s) of its non-type template parameter(s), to hold. […]


2182. Container::[const_]reference types are misleadingly specified

Section: 23.2.1 [container.requirements.general] Status: Review Submitter: Daniel Krügler Opened: 2012-08-20 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with Review status.

Discussion:

According to Table 96 (Container requirements) the return type of X::reference and X::const_reference is "lvalue of T" and "const lvalue of T", respectively. This does not make much sense, because an lvalue is an expression category, not a type. It could also refer to an expression that has a type, but this doesn't make sense either in this context, because obviously X::[const_]reference are intended to refer to types.

Given the fact that vector<bool> has no real reference type for X::[const_]reference and this definition presumably is intended to cover such situations as well, one might think that the wording is just a sloppy form of "type that represents a [const] lvalue of T". But this is also problematic, because basically all proxy reference expressions are rvalues.

It is unclear what the intention is. A straightward way of fixing this wording could make X::[const_]reference identical to [const] T&. This holds for all Library containers except for vector<bool>.

Another way of solving this definition problem would be to impose a requirement that holds for both references and reference-like proxies. Both X::reference and X::const_reference would need to be convertible to const T&. Additionally X::reference would need to support for a mutable container an assignment expression of the form declval<X::reference>() = declval<T>() (this presentation intentionally does not require declval<X::reference&>() = declval<T>()).

Further, the Table 96 does not impose any relations between X::reference and X::const_reference. It seems that at least X::reference needs to be convertible to X::const_reference.

A related question is whether X::reference is supposed to be a mutable reference-like type, irrespective of whether the container is an immutable container or not. The way, type match_results defines reference identical to const_reference indicates one specific interpretation (similarly, the initializer_list template also defines member type reference equal to const value_type&). Note that this can be a different decision as that for iterator and const_iterator, e.g. for sets the type X::reference still is a mutable reference, even though iterator is described as constant iterator.

The proposed resolution is incomplete in regard to the last question.

[2013-03-15 Issues Teleconference]

Moved to Review.

Alisdair notes that this looks like wording in the right direction. Wonders about congruence of these typedefs and the similar ones for iterators.

[2013-09 Chicago]

Moved to Ready.

Consensus that the requirements should require real references, just like iterators, as containers are required to support at least ForwardIterators, which have the same restriction on references.

Matt will file a new issue for some additional concerns with regex match_results.

Proposed resolution:

This wording is relative to N3376.

  1. Change Table 96 — "Container requirements" as indicated:

    Table p6 — Container requirements
    Expression Return type Operational
    Semantics
    Assertion/note
    pre-/post-condition
    Complexity
    X::reference lvalue of T&   compile time
    X::const_reference const lvalue ofconst T&   compile time

2183. Muddled allocator requirements for match_results constructors

Section: 28.10.1 [re.results.const], 28.10.6 [re.results.all] Status: New Submitter: Pete Becker Opened: 2012-08-29 Last modified: 2012-11-14

View other active issues in [re.results.const].

View all other issues in [re.results.const].

View all issues with New status.

Discussion:

28.10.1 [re.results.const] p1 says:

In all match_results constructors, a copy of the Allocator argument shall be used for any memory allocation performed by the constructor or member functions during the lifetime of the object.

There are three constructors:

match_results(const Allocator& = Allocator());
match_results(const match_results& m);
match_results(match_results&& m) noexcept;

The second and third constructors do no have an Allocator argument, so despite the "all match_results constructors", it is not possible to use "the Allocator argument" for the second and third constructors.

The requirements for those two constructors also does not give any guidance. The second constructor has no language about allocators, and the third states that the stored Allocator value is move constructed from m.get_allocator(), but doesn't require using that allocator to allocate memory.

The same basic problem recurs in 28.10.6 [re.results.all], which gives the required return value for get_allocator():

Returns: A copy of the Allocator that was passed to the object's constructor or, if that allocator has been replaced, a copy of the most recent replacement.

Again, the second and third constructors do not take an Allocator, so there is nothing that meets this requirement when those constructors are used.

Proposed resolution:


2184. Muddled allocator requirements for match_results assignments

Section: 28.10.1 [re.results.const], 28.10.6 [re.results.all] Status: New Submitter: Pete Becker Opened: 2012-08-29 Last modified: 2012-11-14

View other active issues in [re.results.const].

View all other issues in [re.results.const].

View all issues with New status.

Discussion:

The effects of the two assignment operators are specified in Table 141. Table 141 makes no mention of allocators, so, presumably, they don't touch the target object's allocator. That's okay, but it leaves the question: match_results::get_allocator() is supposed to return "A copy of the Allocator that was passed to the object's constructor or, if that allocator has been replaced, a copy of the most recent replacement"; if assignment doesn't replace the allocator, how can the allocator be replaced?

Proposed resolution:


2186. Incomplete action on async/launch::deferred

Section: 30.6.8 [futures.async] Status: Open Submitter: Vicente J. Botet Escriba Opened: 2012-09-20 Last modified: 2013-10-15

View other active issues in [futures.async].

View all other issues in [futures.async].

View all issues with Open status.

Discussion:

The description of the effects of async when the launch policy is launch::deferred doesn't state what is done with the result of the deferred function invocation and the possible exceptions as it is done for the asynchronous function when the policy is launch::async.

[2012, Portland: move to Open]

Detlef: agree with the problem but not with the resolution. The wording should be applied to all launch policies rather than having to be separately specified for each one.

Hans: we should redraft to factor out the proposed text outside the two bullets. Needs to be carefully worded to be compatible with the resolution of 2120 (see above).

Moved to open

Proposed resolution:

[This wording is relative to N3376.]

  1. Change 30.6.8 [futures.async] p3 bullet 2 as indicated:

    template <class F, class... Args>
    future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
    async(F&& f, Args&&... args);
    template <class F, class... Args>
    future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
    async(launch policy, F&& f, Args&&... args);
    

    -2- Requires: […]

    -3- Effects:: The first function behaves the same as a call to the second function with a policy argument of launch::async | launch::deferred and the same arguments for F and Args. […] The further behavior of the second function depends on the policy argument as follows (if more than one of these conditions applies, the implementation may choose any of the corresponding policies):

    • if policy & launch::async is non-zero […]

    • if policy & launch::deferred is non-zero — Stores DECAY_COPY(std::forward<F>(f)) and DECAY_COPY(std::forward<Args>(args))... in the shared state. These copies of f and args constitute a deferred function. Invocation of the deferred function evaluates INVOKE(std::move(g), std::move(xyz)) where g is the stored value of DECAY_COPY(std::forward<F>(f)) and xyz is the stored copy of DECAY_COPY(std::forward<Args>(args)).... Any return value is stored as the result in the shared state. Any exception propagated from the execution of the deferred function is stored as the exceptional result in the shared state. The shared state is not made ready until the function has completed. The first call to a non-timed waiting function (30.6.4 [futures.state]) on an asynchronous return object referring to this shared state shall invoke the deferred function in the thread that called the waiting function. Once evaluation of INVOKE(std::move(g), std::move(xyz)) begins, the function is no longer considered deferred. [Note: If this policy is specified together with other policies, such as when using a policy value of launch::async | launch::deferred, implementations should defer invocation or the selection of the policy when no more concurrency can be effectively exploited. — end note]


2188. Reverse iterator does not fully support targets that overload operator&

Section: 24.5.1.3.5 [reverse.iter.opref] Status: Open Submitter: Alisdair Meredith Opened: 2012-09-23 Last modified: 2013-10-15

View all other issues in [reverse.iter.opref].

View all issues with Open status.

Discussion:

The specification for reverse_iterator::operator-> returns the address of the object yielded by dereferencing with operator*, but does not have the usual wording about returning the true address of the object. As reverse_iterator requires the adapted iterator have at least the bidirectional iterator category, we know that the returned reference is a true reference, and not a proxy, hence we can use std::addressof on the reference to get the right answer.

This will most likely show itself as an issue with a list or vector of a type with such an overloaded operator, where algorithms are likely to work with a forward iteration, but not with reverse iteration.

[2013-04-20, Bristol]

Resolution: Goes to open now and move to review as soon as Daniel proposes a new wording.

Proposed resolution:

Revise 24.5.1.3.5 [reverse.iter.opref] p1, as indicated:

Returns: The true address of the object returned by &(operator*()).


2189. Throwing swap breaks unordered containers' state

Section: 23.2.5.1 [unord.req.except] Status: Open Submitter: Alisdair Meredith Opened: 2012-09-23 Last modified: 2013-10-15

View all issues with Open status.

Discussion:

The hash functor and key-comparison functor of unordered containers are allowed to throw on swap.

23.2.5.1 [unord.req.except]p3 "For unordered associative containers, no swap function throws an exception unless that exception is thrown by the swap of the container's Hash or Pred object (if any)."

In such a case we must offer the basic exception safety guarantee, where both objects are left in valid but unspecified states, and no resources are leaked. This yields a corrupt, un-usable container if the first swap succeeds, but the second fails by throwing, as the functors form a matched pair.

So our basic scenario is first, swap the allocators if the allocators propagate on swap, according to allocator_traits. Next we swap the pointers to our internal hash table data structures, so that they match the allocators that allocated them. (Typically, this operation cannot throw). Now our containers are back in a safely destructible state if an exception follows.

Next, let's say we swap the hash functor, and that throws. We have a corrupt data structure, in that the buckets are not correctly indexed by the correct functors, lookups will give unpredicatable results etc. We can safely restore a usable state by forcibly clearing each container - which does not leak resources and leaves us with two (empty but) usable containers.

Now let us assume that the hasher swap succeeds. Next we swap the equality comparator functor, and this too could throw. The important point to bear in mind is that these two functors form an important pairing - two objects that compare equal by the equality functor must also hash to the same value. If we swap one without the other, we most likely leave the container in an unusable state, even if we clear out all elements.

1. A colleague pointed out that the solution for this is to dynamically allocate the two functors, and then we need only swap pointers, which is not a throwing operation. And if we don't want to allocate on default construction (a common QoI request), we might consider moving to a dynamically allocated functors whenever swap is called, or on first insertion. Of course, allocating memory in swap is a whole new can of worms, but this does not really sound like the design we had intended.

2. The simplest option is to say that we do not support hasher or equality functors that throw on ADL swap. Note that the requirement is simply to not throw, rather than to be explicitly marked as noexcept. Throwing functors are allowed, so long as we never use values that would actually manifest a throw when used in an unordered container.

Pablo went on to give me several more options, to be sure we have a full set to consider:

3. Disallow one or the other functor from throwing. In that case, the possibly-throwing functor must be swapped first, then the other functor, the allocator, and the data pointer(s) afterwards (in any order -- there was a TC that allocator assignment and swap may not throw if the corresponding propagation trait is true.). Of course, the question becomes: which functor is allowed to throw and which one is not?

4. Require that any successful functor swap be reliably reversible. This is very inventive. I know of no other place in the standard where such a requirement is stated, though I have occasionally wanted such a guarantee.

5. Allow a failed swap to leave the containers in a state where future insertions may fail for reasons other than is currently allowed. Specifically, if the hash and equality functors are out of sync, all insertions will fail. Presumably some "incompletely swapped" exception would be thrown. This is "slightly" inventive, although people have been discussing "radioactive" states for a while.

[2013-03-15 Issues Teleconference]

Moved to Open.

Proposed resolution:


2191. Incorrect specification of match_results(match_results&&)

Section: 28.10.1 [re.results.const] Status: New Submitter: Pete Becker Opened: 2012-10-02 Last modified: 2012-11-14

View other active issues in [re.results.const].

View all other issues in [re.results.const].

View all issues with New status.

Discussion:

28.10.1 [re.results.const]/3: "Move-constructs an object of class match_results satisfying the same postconditions as Table 141."

Table 141 lists various member functions and says that their results should be the results of the corresponding member function calls on m. But m has been moved from, so the actual requirement ought to be based on the value that m had before the move construction, not on m itself.

In addition to that, the requirements for the copy constructor should refer to Table 141.

Ganesh:

Also, the requirements for move-assignment should refer to Table 141. Further it seems as if in Table 141 all phrases of "for all integers n < m.size()" should be replaced by "for all unsigned integers n < m.size()".

Proposed resolution:


2192. Validity and return type of std::abs(0u) is unclear

Section: 26.8 [c.math] Status: Open Submitter: Daniel Krügler Opened: 2012-10-02 Last modified: 2014-01-20

View other active issues in [c.math].

View all other issues in [c.math].

View all issues with Open status.

Discussion:

In C++03 the following two programs are invalid:

  1. #include <cmath>
    
    int main() {
      std::abs(0u);
    }
    
  2. #include <cstdlib>
    
    int main() {
      std::abs(0u);
    }
    

because none of the std::abs() overloads is a best match.

In C++11 the additional "sufficient overload" rule from 26.8 [c.math] p11 (see also LWG 2086) can be read to be applicable to the std::abs() overloads as well, which can lead to the following possible conclusions:

  1. The program

    #include <type_traits>
    #include <cmath>
    
    static_assert(std::is_same<decltype(std::abs(0u)), double>(), "Oops");
    
    int main() {
      std::abs(0u); // Calls std::abs(double)
    }
    

    is required to be well-formed, because of sub-bullet 2 ("[..] or an integer type [..]") of 26.8 [c.math] p11 (Note that the current resolution of LWG 2086 doesn't fix this problem).

  2. Any translation unit including both <cmath> and <cstdlib> might be ill-formed because of two conflicting requirements for the return type of the overload std::abs(int).

It seems to me that at least the second outcome is not intended, personally I think that both are unfortunate: In contrast to all other floating-point functions explicitly listed in sub-clause 26.8 [c.math], the abs overloads have a special and well-defined meaning for signed integers and thus have explicit overloads returning a signed integral type. I also believe that there is no problem accepting that std::fabs(0u) is well-defined with return type double, because the leading 'f' clearly signals that we have a floating point function here. But the expected return type of std::abs(0u) seems less than clear to me. A very reasonable answer could be that this has the same type as its argument type, alternatively it could be a reasonably chosen signed integer type, or a floating point type. It should also be noted, that the corresponding "generic type function" rule set from C99/C1x in 7.25 p2+3 is restricted to the floating-point functions from <math.h> and <complex.h>, so cannot be applied to the abs functions (but to the fabs functions!).

Selecting a signed integer return type for unsigned input values can also problematic: The directly corresponding signed integer type would give half of the possible argument values an implementation-defined result value. Choosing the first signed integer value that can represent all positive values would solve this problem for unsigned int, but there would be no clear answer for the input type std::uintmax_t.

Based on this it seems to me that the C++03 state in regard to unsigned integer values was the better situation, alerting the user that this code is ambigious at the moment (This might be change with different core-language rules as described in N3387).

[2013-04-20, Bristol]

Resolution: leave as new and bring it back in Chicago.

[2013-09 Chicago]

This issue also relates to LWG 2294

STL: these two issues should be bundled

Stefanus: do what Pete says, and add overloads for unsigned to return directly

STL: agree Consensus that this is an issue

Walter: motion to move to Open

STL: no wording for 2294

Stefanus: move to open and note the 2 issues are related and should be moved together

Stefanus: add and define unsigned versions of abs()

Proposed resolution:

This wording is relative to N3376.

  1. Change 26.8 [c.math] p11 as indicated:

    -11- Moreover, except for the abs functions, there shall be additional overloads sufficient to ensure:

    […]


2193. Default constructors for standard library containers are explicit

Section: 23 [containers] Status: EWG Submitter: Richard Smith Opened: 2012-10-04 Last modified: 2013-10-15

View other active issues in [containers].

View all other issues in [containers].

Discussion:

Most (all?) of the standard library containers have explicit default constructors. Consequently:

std::set<int> s1 = { 1, 2 }; // ok
std::set<int> s2 = { 1 }; // ok
std::set<int> s3 = {}; // ill-formed, copy-list-initialization selected an explicit constructor

Note that Clang + libc++ rejects the declaration of s3 for this reason. This cannot possibly match the intent.

Suggested fix: apply this transformation throughout the standard library:

set() : set(Compare()) {}
explicit set(const Compare& comp = Compare(),
             const Allocator& = Allocator());

[ 2012-10-06: Daniel adds concrete wording. ]

[2012, Portland: Move to Open]

This may be an issue better solved by a core language tweak. Throw the issue over to EWG and see whether they believe the issue is better resolved in Core or Library.

AJM suggest we spawn a new status of 'EWG' to handle such issues - and will move this issue appropriately when the software can record such resolutions.

[2013-08-27, Joaquín M López Muñoz comments:]

For the record, I'd like to point out that the resolution proposed by the submitter, namely replacing

explicit basic_string(const Allocator& a = Allocator());

by

basic_string() : basic_string(Allocator()) {}
explicit basic_string(const Allocator& a);

(and similarly for other container and container-like classes) might introduce a potential backwards-compatibility problem related with explicit instantiation. Consider for instance

struct my_allocator
{
  my_allocator(...); // no default ctor
  ...
};

template class std::basic_string<char, std::char_traits<char>, my_allocator<char>>;

This (which I understand is currently a valid explicit instantiation of std::basic_string) will break if std::basic_string ctors are modified as proposed by this issue, since my_allocator doesn't have a default ctor.

[2013-10-06, Daniel comments:]

Issue 2303 describes the more general problem related to explicit instantiation requests in the current library and may help to solve this problem here as well.

Proposed resolution:

This wording is relative to N3376.

The more general criterion for performing the suggested transformation was: Any type with an initializer-list constructor that also has an explicit default constructor.

  1. Change class template basic_string synopsis, 21.4 [basic.string] p5 as indicated:

    basic_string() : basic_string(Allocator()) {}
    explicit basic_string(const Allocator& a = Allocator());
    
  2. Change 21.4.2 [string.cons] before p1 as indicated:

    explicit basic_string(const Allocator& a = Allocator());
    
  3. Change class template deque synopsis, 23.3.3.1 [deque.overview] p2 as indicated:

    deque() : deque(Allocator()) {}
    explicit deque(const Allocator& = Allocator());
    
  4. Change 23.3.3.2 [deque.cons] before p1 as indicated:

    explicit deque(const Allocator& = Allocator());
    
  5. Change class template forward_list synopsis, 23.3.4.1 [forwardlist.overview] p3 as indicated:

    forward_list() : forward_list(Allocator()) {}
    explicit forward_list(const Allocator& = Allocator());
    
  6. Change 23.3.4.2 [forwardlist.cons] before p1 as indicated:

    explicit forward_list(const Allocator& = Allocator());
    
  7. Change class template list synopsis, 23.3.5.1 [list.overview] p2 as indicated:

    list() : list(Allocator()) {}
    explicit list(const Allocator& = Allocator());
    
  8. Change 23.3.5.2 [list.cons] before p1 as indicated:

    explicit list(const Allocator& = Allocator());
    
  9. Change class template vector synopsis, 23.3.6.1 [vector.overview] p2 as indicated:

    vector() : vector(Allocator()) {}
    explicit vector(const Allocator& = Allocator());
    
  10. Change 23.3.6.2 [vector.cons] before p1 as indicated:

    explicit vector(const Allocator& = Allocator());
    
  11. Change class template specialization vector<bool> synopsis, 23.3.7 [vector.bool] p1 as indicated:

    vector() : vector(Allocator()) {}
    explicit vector(const Allocator& = Allocator());
    
  12. Change class template map synopsis, 23.4.4.1 [map.overview] p2 as indicated:

    map() : map(Compare()) {}
    explicit map(const Compare& comp = Compare(),
                 const Allocator& = Allocator());
    
  13. Change 23.4.4.2 [map.cons] before p1 as indicated:

    explicit map(const Compare& comp = Compare(),
                 const Allocator& = Allocator());
    
  14. Change class template multimap synopsis, 23.4.5.1 [multimap.overview] p2 as indicated:

    multimap() : multimap(Compare()) {}
    explicit multimap(const Compare& comp = Compare(),
                      const Allocator& = Allocator());
    
  15. Change 23.4.5.2 [multimap.cons] before p1 as indicated:

    explicit multimap(const Compare& comp = Compare(),
                      const Allocator& = Allocator());
    
  16. Change class template set synopsis, 23.4.6.1 [set.overview] p2 as indicated:

    set() : set(Compare()) {}
    explicit set(const Compare& comp = Compare(),
                 const Allocator& = Allocator());
    
  17. Change 23.4.6.2 [set.cons] before p1 as indicated:

    explicit set(const Compare& comp = Compare(),
                 const Allocator& = Allocator());
    
  18. Change class template multiset synopsis, 23.4.7.1 [multiset.overview] p2 as indicated:

    multiset() : multiset(Compare()) {}
    explicit multiset(const Compare& comp = Compare(),
                      const Allocator& = Allocator());
    
  19. Change 23.4.7.2 [multiset.cons] before p1 as indicated:

    explicit multiset(const Compare& comp = Compare(),
                      const Allocator& = Allocator());
    
  20. Change class template unordered_map synopsis, 23.5.4.1 [unord.map.overview] p3 as indicated:

    unordered_map() : unordered_map(see below) {}
    explicit unordered_map(size_type n = see below,
                           const hasher& hf = hasher(),
                           const key_equal& eql = key_equal(),
                           const allocator_type& a = allocator_type());
    
  21. Change 23.5.4.2 [unord.map.cnstr] before p1 as indicated:

    unordered_map() : unordered_map(see below) {}
    explicit unordered_map(size_type n = see below,
                           const hasher& hf = hasher(),
                           const key_equal& eql = key_equal(),
                           const allocator_type& a = allocator_type());
    
  22. Change class template unordered_multimap synopsis, 23.5.5.1 [unord.multimap.overview] p3 as indicated:

    unordered_multimap() : unordered_multimap(see below) {}
    explicit unordered_multimap(size_type n = see below,
                                const hasher& hf = hasher(),
                                const key_equal& eql = key_equal(),
                                const allocator_type& a = allocator_type());
    
  23. Change 23.5.5.2 [unord.multimap.cnstr] before p1 as indicated:

    unordered_multimap() : unordered_multimap(see below) {}
    explicit unordered_multimap(size_type n = see below,
                                const hasher& hf = hasher(),
                                const key_equal& eql = key_equal(),
                                const allocator_type& a = allocator_type());
    
  24. Change class template unordered_set synopsis, 23.5.6.1 [unord.set.overview] p3 as indicated:

    unordered_set() : unordered_set(see below) {}
    explicit unordered_set(size_type n = see below,
                           const hasher& hf = hasher(),
                           const key_equal& eql = key_equal(),
                           const allocator_type& a = allocator_type());
    
  25. Change 23.5.6.2 [unord.set.cnstr] before p1 as indicated:

    unordered_set() : unordered_set(see below) {}
    explicit unordered_set(size_type n = see below,
                           const hasher& hf = hasher(),
                           const key_equal& eql = key_equal(),
                           const allocator_type& a = allocator_type());
    
  26. Change class template unordered_multiset synopsis, 23.5.7.1 [unord.multiset.overview] p3 as indicated:

    unordered_multiset() : unordered_multiset(see below) {}
    explicit unordered_multiset(size_type n = see below,
                                const hasher& hf = hasher(),
                                const key_equal& eql = key_equal(),
                                const allocator_type& a = allocator_type());
    
  27. Change 23.5.7.2 [unord.multiset.cnstr] before p1 as indicated:

    unordered_multiset() : unordered_multiset(see below) {}
    explicit unordered_multiset(size_type n = see below,
                                const hasher& hf = hasher(),
                                const key_equal& eql = key_equal(),
                                const allocator_type& a = allocator_type());
    

2195. Missing constructors for match_results

Section: 28.10 [re.results] Status: Open Submitter: Daniel Krügler Opened: 2012-10-06 Last modified: 2014-01-20

View other active issues in [re.results].

View all other issues in [re.results].

View all issues with Open status.

Discussion:

The requirement expressed in 28.10 [re.results] p2

The class template match_results shall satisfy the requirements of an allocator-aware container and of a sequence container, as specified in 23.2.3 [sequence.reqmts], except that only operations defined for const-qualified sequence containers are supported.

can be read to require the existence of the described constructors from as well, but they do not exist in the synopsis.

The missing sequence constructors are:

match_results(initializer_list<value_type>);
match_results(size_type, const value_type&);
template<class InputIterator> match_results(InputIterator, InputIterator);

The missing allocator-aware container constructors are:

match_results(const match_results&, const Allocator&);
match_results(match_results&&, const Allocator&);

It should be clarified, whether (a) constructors are an exception of above mentioned operations or (b) whether at least some of them (like those accepting a match_results value and an allocator) should be added.

As visible in several places of the standard (including the core language), constructors seem usually to be considered as "operations" and they certainly can be invoked for const-qualified objects.

The below given proposed resolution applies only the minimum necessary fix, i.e. it excludes constructors from above requirement.

[2013-04-20, Bristol]

Check current implementations to see what they do and, possibly, write a paper.

[2013-09 Chicago]

Ask Daniel to update the proposed wording to include the allocator copy and move constructors.

[2014-01-18 Daniel changes proposed resolution]

Previous resolution:

  1. Change 28.10 [re.results] p2 as indicated:

    The class template match_results shall satisfy the requirements of an allocator-aware container and of a sequence container, as specified in 23.2.3 [sequence.reqmts], except that only operations defined for const-qualified sequence containers that are not constructors are supported.

Proposed resolution:

This wording is relative to N3376.

  1. Change 28.10 [re.results] p4, class template match_results synopsis, as indicated:

    […]
    // 28.10.1, construct/copy/destroy:
    explicit match_results(const Allocator& a = Allocator());
    match_results(const match_results& m);
    match_results(const match_results& m, const Allocator& a);
    match_results(match_results&& m) noexcept;
    match_results(match_results&& m, const Allocator& a) noexcept;
    […]
    
  2. Change 28.10.1 [re.results.const] as indicated: [Drafting note: Paragraph 6 as currently written, makes not much sense, because the noexcept does not allow any exception to propagate. Further-on, the allocator requirements do not allow for throwing move constructors. Deleting it seems to be near to editorial — end drafting note]

    match_results(const match_results& m);
    match_results(const match_results& m, const Allocator& a);
    

    -4- Effects: Constructs an object of class match_results, as a copy of m.

    match_results(match_results&& m) noexcept;
    match_results(match_results&& m, const Allocator& a) noexcept;
    

    -5- Effects: Move-constructs an object of class match_results from m satisfying the same postconditions as Table 142. AdditionallyFor the first form, the stored Allocator value is move constructed from m.get_allocator().

    -6- Throws: Nothing if the allocator's move constructor throws nothing.


2198. max_load_factor(z) makes no strong guarantees, but bans useful behavior

Section: 23.2.5 [unord.req] Status: Open Submitter: Alisdair Meredith Opened: 2012-10-09 Last modified: 2013-10-15

View other active issues in [unord.req].

View all other issues in [unord.req].

View all issues with Open status.

Discussion:

The user cannot specify a max_load_factor for their unordered container at construction, it must be supplied after the event, when the container is potentially not empty. The contract for this method is deliberately vague, not guaranteeing to use the value supplied by the user, and any value actually used will be used as a ceiling that the container will attempt to respect.

The only guarantee we have is that, if user requests a max_load_factor that is less than the current load_factor, then the operation will take constant time, thus outlawing an implementation that chooses to rehash and so preserve as a class invariant that load_factor < max_load_factor.

Reasonable options conforming to the standard include ignoring the user's request if the requested value is too low, or deferring the rehash to the next insert operation and allowing the container to have a strange state (wrt max_load_factor) until then - and there is still the question of rehashing if the next insert is for a duplicate key in a unique container.

Given the deliberate vagueness of the current wording, to support a range of reasonable (but not perfect) behaviors, it is not clear why the equally reasonable rehash to restore the constraint should be outlawed. It is not thought that this is a performance critical operation, where users will be repeatedly setting low load factors on populated containers, in a tight or (less unlikely) an instant response scenario.

[2013-03-15 Issues Teleconference]

Moved to Open.

Alisdair to provide wording.

Proposed resolution:


2199. unordered containers are required to have an initial max load factor of 1.0

Section: 23.2.5 [unord.req] Status: Open Submitter: Alisdair Meredith Opened: 2012-10-09 Last modified: 2013-10-15

View other active issues in [unord.req].

View all other issues in [unord.req].

View all issues with Open status.

Discussion:

The default constructor, allocator-aware constructor, and range-based constructors for the unordered containers do not offer a means to control the initial max_load_factor, so the standard mandates the value 1.0. This seems overly restrictive, as there is plenty of research suggesting a value between 0.5 and 1.0 is more often optimal for unique-key containers, and perhaps a slightly higher value might be appropriate for multi-containers.

Rather than guess at the appropriate max_load_factor, it seems reasonable that the standard should allow vendors to pick a value at their discretion, with perhaps a note of advice. It is less clear whether the default value should be implementation-defined or unspecified, given the ease of a user determining this by querying this attribute immediately after construction.

[2013-03-15 Issues Teleconference]

Moved to Open.

Alisdair to provide wording.

Marshall: It seems to me that what you really want is to be able to pass a max load factor in the constructor, but that's a different issue.

Alisdair agrees in principle, but concerned with adding yet more constructors to these classes.

Proposed resolution:


2201. Missing macro entries from C standard library

Section: C.4 [diff.library] Status: New Submitter: Kevin McCarty Opened: 2012-02-03 Last modified: 2013-10-15

View all other issues in [diff.library].

View all issues with New status.

Discussion:

It seems that in C.4 [diff.library], Table 150 the following macros from 18.3.3 [c.limits], Table 31 are missing:

LLONG_MIN 
LLONG_MAX
ULLONG_MAX

In addition in C.4 [diff.library], Table 150 the following macros from 18.3.3 [c.limits], Table 32 are missing:

DECIMAL_DIG 
FLT_EVAL_METHOD

Furtheron it seems that in C.4 [diff.library], Table 149/150 further macros are missing as well, e.g. HUGE_VALF, INFINITY, etc.

Proposed resolution:


2202. Missing allocator support by async

Section: 30.6.8 [futures.async] Status: Deferred Submitter: Detlef Vollmann Opened: 2012-10-19 Last modified: 2014-01-20

View other active issues in [futures.async].

View all other issues in [futures.async].

View all issues with Deferred status.

Discussion:

promise, packaged_task, and async are the only places where a shared state is actually supposed to be allocated. Accordingly, promise and packaged_task are "allocator-aware". But function template async provides no way to provide an allocator.

[2013-09 Chicago]

Matt: deprecate async

Nico: read my paper

Alisdair: defer issues to wait for polymorphic allocators

Alisdair: defer, active topic of research Deferred

Proposed resolution:


2204. reverse_iterator should not require a second copy of the base iterator

Section: 24.5.1.3.4 [reverse.iter.op.star] Status: Tentatively NAD Submitter: David Abrahams Opened: 2012-10-30 Last modified: 2013-10-15

View all issues with Tentatively NAD status.

Discussion:

This note in 24.5.1.3.4 [reverse.iter.op.star]/2:

[ Note: This operation must use an auxiliary member variable rather than a temporary variable to avoid returning a reference that persists beyond the lifetime of its associated iterator. (See 24.2.) —end note ]

is incorrect because such iterator implementations are ruled out by 24.2.5 [forward.iterators]/6, where it says:

If a and b are both dereferenceable, then a == b if and only if *a and *b are bound to the same object.

[2013-04-20, Bristol]

Alisdair: sugested to strike the "exposition only" member.

Daniel: we must check that it wouldn't conflict with a previous solution to another issue.

Dietmar: This is an issue but the proposing word is not correct. When we have proxies inside the sequence.

Solution: NAD thanks to a contrieved example by Dietmar.

Proposed resolution:

Strike the note, 24.5.1.3.4 [reverse.iter.op.star]/2:

[ Note: This operation must use an auxiliary member variable rather than a temporary variable to avoid returning a reference that persists beyond the lifetime of its associated iterator. (See 24.2.) —end note ]

2205. Problematic postconditions of regex_match and regex_search

Section: 28.11.2 [re.alg.match], 28.11.3 [re.alg.search] Status: New Submitter: Pete Becker Opened: 2012-10-24 Last modified: 2013-10-15

View other active issues in [re.alg.match].

View all other issues in [re.alg.match].

View all issues with New status.

Discussion:

Table 142 lists post-conditions on the match_results object when a call to regex_match succeeds. regex_match is required to match the entire target sequence. The post-condition for m[0].matched is "true if a full match was found." Since these are conditions for a successful search which is, by definition, a full match, the post-condition should be simply "true".

There's an analogous probem in Table 143: the condition for m[0].matched is "true if a match was found, false otherwise." But Table 143 gives post-conditions for a successful match, so the condition should be simply "true".

Furthermore, they have explicit requirements for m[0].first, m[0].second, and m[0].matched. They also have requirements for the other elements of m, described as m[n].first, m[n].second, and m[n].matched, in each case qualifying the value of n as "for n < m.size()". Since there is an explicit description for n == 0, this qualification should be "for 0 < n < m.size()" in all 6 places.

Proposed resolution:

This wording is relative to N3376.

  1. Change Table 142 as indicated:

    Table 142 — Effects of regex_match algorithm
    Element Value
    m[0].first first
    m[0].second last
    m[0].matched true if a full match was found.
    m[n].first For all integers 0 < n < m.size(), the start of the sequence that matched sub-expression n.
    Alternatively, if subexpression n did not participate in the match, then last.
    m[n].second For all integers 0 < n < m.size(), the end of the sequence that matched sub-expression n.
    Alternatively, if sub-expression n did not participate in the match, then last.
    m[n].matched For all integers 0 < n < m.size(), true if sub-expression n participated in the match, false otherwise.
  2. Change Table 143 as indicated:

    Table 143 — Effects of regex_search algorithm
    Element Value
    m[0].first The start of the sequence of characters that matched the regular expression
    m[0].second The end of the sequence of characters that matched the regular expression
    m[0].matched true if a match was found, and false otherwise.
    m[n].first For all integers 0 < n < m.size(), the start of the sequence that matched sub-expression n.
    Alternatively, if subexpression n did not participate in the match, then last.
    m[n].second For all integers 0 < n < m.size(), the end of the sequence that matched sub-expression n.
    Alternatively, if sub-expression n did not participate in the match, then last.
    m[n].matched For all integers 0 < n < m.size(), true if sub-expression n participated in the match, false otherwise.

2206. Inaccuracy in initializer_list constructor requirements

Section: 23.2.3 [sequence.reqmts], 23.2.4 [associative.reqmts], 23.2.5 [unord.req], 26.5.1.2 [rand.req.seedseq] Status: Open Submitter: Jeffrey Yasskin Opened: 2012-10-21 Last modified: 2013-10-15

View other active issues in [sequence.reqmts].

View all other issues in [sequence.reqmts].

View all issues with Open status.

Discussion:

In 23.2.3 [sequence.reqmts] p3, we have "il designates an object of type initializer_list<value_type>", and then several functions that take 'il' as an argument. However, an expression like {1, 2, 'a'} is not an object of type initializer_list<int> unless it's used to initialize an explicitly-typed variable of that type. I believe we want:

std::vector<int> v;
v = {1, 2, 'a'};

to compile portably, so we should say something different when defining 'il'. The same phrasing happens in 23.2.4 [associative.reqmts], 23.2.5 [unord.req], and 26.5.1.2 [rand.req.seedseq].

This may just be an editorial issue because the actual class synopses declare the functions to take initializer_list<exact_type>.

[2013-03-15 Issues Teleconference]

Moved to Open.

This is definitely not NAD

Should copy the suggested wording as the proposed resolution.

Proposed resolution:


2208. std::reverse_iterator should be a literal type

Section: 24.5.1 [reverse.iterators] Status: New Submitter: Jeffrey Yasskin Opened: 2012-10-30 Last modified: 2013-10-15

View other active issues in [reverse.iterators].

View all other issues in [reverse.iterators].

View all issues with New status.

Discussion:

std::reverse_iterator::reverse_iterator(Iterator) should be constexpr so that other constexpr functions can return reverse_iterators. Of the other methods, the other constructors, base(), operator+, operator-, operator[], and the non-member operators can probably also be constexpr.

operator* cannot be constexpr because it involves an assignment to a member variable. Discussion starting with c++std-lib-33282 indicated that it would be useful to make reverse_iterator a literal type despite this restriction on its use at compile time.

Proposed resolution:


2212. tuple_size for const pair request <tuple> header

Section: 20.2 [utility] Status: Open Submitter: Alisdair Meredith Opened: 2012-11-09 Last modified: 2013-11-28

View all other issues in [utility].

View all issues with Open status.

Discussion:

The <utility> header declares sufficient of the tuple API to specialize the necessary templates for pair, notably tuple_size and tuple_element. However, it does not make available the partial specializations that support cv-qualified template arguments, so while I can write the following after including only <utility>:

#include <utility>

using TestType = std::pair<int, int>;
static_assert(2 == std::tuple_size<TestType>(), "Pairs have two elements");
std::tuple_element<0, TestType>::type var{1};

the following may fail to compile unless I also include <tuple>:

#include <utility>

using TestType = const std::pair<int, int>;
static_assert(2 == std::tuple_size<TestType>(), "Pairs have two elements");
std::tuple_element<0, TestType>::type var{1};

Note, however, that the latter may compile with some standard library implementations but not others, leading to subtle portability issues.

[2013-03-15 Issues Teleconference]

Moved to Open.

Howard notes that we have the same issue with array, so any resolution should apply to that header too.

[2013-10-18 Daniel provides wording]

The suggested wording uses a similar approach as we already have in 24.7 [iterator.range] to ensure that the range access templates are available when at least one of an enumerated list of header files is included.

I also think that the restricted focus on tuple_size of this issue is too narrow and should be extended to the similar partial template specializations of tuple_element as well. Therefore the suggested wording ensures this as well.

Proposed resolution:

This wording is relative to N3797.

  1. Change 20.4.2.5 [tuple.helper] as indicated:

    template <class T> class tuple_size<const T>;
    template <class T> class tuple_size<volatile T>;
    template <class T> class tuple_size<const volatile T>;
    

    -3- Let TS denote tuple_size<T> of the cv-unqualified type T. Then each of the three templates shall meet the UnaryTypeTrait requirements (20.10.1) with a BaseCharacteristic of

    integral_constant<remove_cv<decltype(TS::value)>::type, TS::value>
    

    -?- In addition to being available via inclusion of the <tuple> header, each of the three templates are available when any of the headers <array> or <utility> are included.

    template <size_t I, class T> class tuple_element<I, const T>;
    template <size_t I, class T> class tuple_element<I, volatile T>;
    template <size_t I, class T> class tuple_element<I, const volatile T>;
    

    -?- Let TE denote tuple_element<I, T> of the cv-unqualified type T. Then each of the three templates shall meet the TransformationTrait requirements (20.10.1) with a member typedef type that names the following type:

    • for the first specialization, add_const<TE::type>::type,

    • for the second specialization, add_volatile<TE::type>::type, and

    • for the third specialization, add_cv<TE::type>::type.

    -?- In addition to being available via inclusion of the <tuple> header, each of the three templates are available when any of the headers <array> or <utility> are included.


2213. Return value of std::regex_replace

Section: 28.11.4 [re.alg.replace] Status: New Submitter: Pete Becker Opened: 2012-11-08 Last modified: 2013-10-15

View other active issues in [re.alg.replace].

View all other issues in [re.alg.replace].

View all issues with New status.

Discussion:

In 28.11.4 [re.alg.replace], the first two variants of std::regex_replace take an output iterator named "out" as their first argument. Paragraph 2 of that section says that the functions return "out". When I first implemented this, many years ago, I wrote it to return the value of the output iterator after all the insertions (cf. std::copy), which seems like the most useful behavior. But looking at the requirement now, it like the functions should return the original value of "out" (i.e. they have to keep a copy of the iterator for no reason except to return it). Is that really what was intended?

Proposed resolution:

This wording is relative to N3485.

  1. Edit 28.11.4 [re.alg.replace] as indicated:

    template <class OutputIterator, class BidirectionalIterator,
      class traits, class charT, class ST, class SA>
    OutputIterator
    regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last,
      const basic_regex<charT, traits>& e, const basic_string<charT, ST, SA>& fmt,
      regex_constants::match_flag_type flags = regex_constants::match_default);
    template <class OutputIterator, class BidirectionalIterator,
      class traits, class charT>
    OutputIterator
    regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last,
      const basic_regex<charT, traits>& e, const charT* fmt,
      regex_constants::match_flag_type flags = regex_constants::match_default);
    

    -1- Effects: Constructs a regex_iterator object i as if by regex_iterator<BidirectionalIterator, charT, traits> i(first, last, e, flags), and uses i to enumerate through all of the matches m of type match_results<BidirectionalIterator> that occur within the sequence [first, last). If no such matches are found and !(flags & regex_constants ::format_no_copy) then calls out = std::copy(first, last, out). If any matches are found then, for each such match, if !(flags & regex_constants::format_no_copy), calls out = std::copy(m.prefix().first, m.prefix().second, out), and then calls out = m.format(out, fmt, flags) for the first form of the function and out = m.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags) for the second. Finally, if such a match is found and !(flags & regex_constants ::format_no_copy), calls out = std::copy(last_m.suffix().first, last_m.suffix().second, out) where last_m is a copy of the last match found. If flags & regex_constants::format_first_only is non-zero then only the first match found is replaced.

    -2- Returns: out.


2214. Clarify basic_ios::init call restrictions

Section: 27.5.5.2 [basic.ios.cons] Status: Open Submitter: Andrey Semashev Opened: 2012-11-09 Last modified: 2013-10-15

View all other issues in [basic.ios.cons].

View all issues with Open status.

Discussion:

There is an ambiguity in how std::basic_ios::init method (27.5.5.2 [basic.ios.cons]) can be used in the derived class. The Standard only specify the state of the basic_ios object after the call completes. However, in basic_ios default constructor description (27.5.5.2 [basic.ios.cons]) there is this sentence:

Effects: Constructs an object of class basic_ios (27.5.3.7 [ios.base.cons]) leaving its member objects uninitialized. The object shall be initialized by calling basic_ios::init before its first use or before it is destroyed, whichever comes first; otherwise the behavior is undefined.

This restriction hints that basic_ios::init should be called exactly once before the object can be used or destroyed, because basic_ios::init may not know whether it was called before or not (i.e. whether its members are actually uninitialized or are initialized by the previous call to basic_ios::init). There is no such restriction in the basic_ios::init preconditions so it is not clear whether it is allowed to call basic_ios::init multiple times or not.

This problem has already affected publicly available implementations. For example, Microsoft Visual C++ STL introduces a memory leak if basic_ios::init is called multiple times, while GCC 4.7 and STLPort reinitialize the basic_ios object correctly without memory leak or any other undesired effects. There was a discussion of this issue on Boost developers mailing list, and there is a test case that reproduces the problem. The test case is actually a bug report for my Boost.Log library, which attempts to cache basic_ostream-derived objects internally to avoid expensive construction and destruction. My stream objects allowed resetting the stream buffer pointers the stream is attached to, without requiring to destroy and construct the stream.

My personal view of the problem and proposed resolution follows.

While apparently the intent of basic_ios::init is to provide a way to initialize basic_ios after default construction, I see no reason to forbid it from being called multiple times to reinitialize the stream. Furthermore, it is possible to implement a conforming basic_ios that does not have this restriction.

The quoted above section of the Standard that describes the effects of the default constructor is misleading. The Standard does not mandate any data members of basic_ios or ios_base (27.5.3 [ios.base]), which it derives from. This means that the implementation is allowed to use non-POD data members with default constructors that initialize the members with particular default values. For example, in the case of Microsoft Visual C++ STL the leaked memory is an std::locale instance that is dynamically allocated during basic_ios::init, a raw pointer to which is stored within ios_base. It is possible to store e.g. an unique_ptr instead of a raw pointer as a member of ios_base, the smart pointer will default initialize the underlying raw pointer on default construction and automatically destroy the allocated object upon being reset or destroyed, which would eliminate the leak and allow basic_ios::init to be called multiple times. This leads to conclusion that the default constructor of basic_ios cannot leave "its member objects uninitialized" but instead performs default initialization of the member objects, which would mean the same thing in case of POD types.

However, I feel that restricting ios_base and basic_ios members to non-POD types is not acceptable. Since multiple calls to basic_ios::init are not forbidden by the Standard, I propose to correct the basic_ios default constructor description so that it is allowed to destroy basic_ios object without calling basic_ios::init. This would imply that any raw members of basic_ios and ios_base should be initialized to values suitable for destruction (essentially, this means only initializing raw pointers to NULL). The new wording could look like this:

Effects: Constructs an object of class basic_ios (27.5.3.7 [ios.base.cons]) initializing its member objects to unspecified state, only suitable for basic_ios destruction. The object shall be initialized by calling basic_ios::init before its first use; otherwise the behavior is undefined.

This would remove the hint that basic_ios::init must be called exactly once. Also, this would remove the requirement for basic_ios::init to be called at all before the destruction. This is also an important issue because the derived stream constructor may throw an exception before it manages to call basic_ios::init (for example, if the streambuf constructor throws), and in this case the basic_ios destructor has undefined behavior.

To my mind, the described modification is sufficient to resolve the issue. But to emphasize the possibility to call basic_ios::init multiple times, a remark or a footnote for basic_ios::init postconditions could be added to explicitly state the semantics of calling it multiple times. The note could read as follows:

The function can be called multiple times during the object lifetime. Each subsequent call reinitializes the object to the described in postconditions initial state.

[2013-04-20, Bristol]

Alisdair: The current wording is unclear but the proposed resolution is wrong

Solution: Clarify that init must be called once and only once. Move then to review.

Proposed resolution:

This wording is relative to N3485.

  1. Edit 27.5.5.2 [basic.ios.cons] as indicated:

    basic_ios();
    

    -2- Effects: Constructs an object of class basic_ios (27.5.3.7 [ios.base.cons]) leaving its member objects uninitializedinitializing its member objects to unspecified state, only suitable for basic_ios destruction. The object shall be initialized by calling basic_ios::init before its first use or before it is destroyed, whichever comes first; otherwise the behavior is undefined.

    void init(basic_streambuf<charT,traits>* sb);
    

    Postconditions: The postconditions of this function are indicated in Table 128.

    -?- Remarks: The function can be called multiple times during the object lifetime. Each subsequent call reinitializes the object to the described in postconditions initial state.


2215. (unordered) associative container functors should be CopyConstructible

Section: 23.2.4 [associative.reqmts], 23.2.5 [unord.req] Status: Open Submitter: Alisdair Meredith Opened: 2012-11-14 Last modified: 2013-10-15

View other active issues in [associative.reqmts].

View all other issues in [associative.reqmts].

View all issues with Open status.

Discussion:

The requirements on the functors used to arrange elements in the various associative and unordered containers are given by a set of expressions in tables 102 - Associative container requirements, and 103 - Unordered associative container requirements. In keeping with Library convention these expressions make the minimal requirements necessary on their types. For example, we have the following 3 row extracts for the unordered containers:

Expression Assertion/note pre-/post-condition
X(n, hf, eq)
X a(n, hf, eq)
Requires: hasher and key_equal are CopyConstructible.
X(n, hf)
X a(n, hf)
Requires: hasher is CopyConstructible and key_equal is DefaultConstructible.
X(n)
X a(n)
Requires: hasher and key_equal are DefaultConstructible.

However, the signature for each class template requires that the functors must effectively be CopyConstructible for each of these expressions:

template <class Key,
          class T,
          class Hash  = hash<Key>,
          class Pred  = std::equal_to<Key>,
          class Allocator = std::allocator<std::pair<const Key, T> > >
class unordered_map
{
  ...

  // construct/destroy/copy
  explicit unordered_map(size_type n = see below,
                         const hasher& hf = hasher(),
                         const key_equal& eql = key_equal(),
                         const allocator_type& a = allocator_type());

  ...
}

The letter of the standard can be honoured as long as implementors recognize their freedom to split this one signature into multiple overloads, so that the documented default arguments (requiring a CopyConstructible functor) are not actually passed as default arguments.

As we look into the requirements for the copy constructor and copy-assignment operator, the requirements are even more vague, as the explicit requirements on the functors are not called out, other than saying that the functors are copied.

Must the functors be CopyAssignable? Or is CopyConstructible sufficient in this case? Do we require that the functors be Swappable so that the copy-swap idiom can be deployed here? Note that a type that is both CopyConstructible and CopyAssignable is still not guaranteed to be Swappable as the user may delete the swap function for their type in their own namespace, which would be found via ADL.

Some clean-up of the requirements table looks necessary, to at least document the assignment behavior. In addition, we should have clear guidance on whether these functors should always be CopyConstructible, as suggested by the class template definitions, or if the requirement tables are correct and we should explicitly split up the constructors in the (unordered) associative containers to no longer use default (function) arguments to obtain their defaulted functors.

I recommend the simplest solution would be to always require that the functors for (unorderd) associative containers be CopyConstructible, above the requirements tables themselves, so that the issue need not be addressed within the tables. I suggest that the assignment operators for these containers add the requirement that the functors be Swappable, rather than forwarding the corresponding Assignable requirement.

[2013-03-15 Issues Teleconference]

Moved to Open.

Alisdair to propose wording.

Proposed resolution:


2216. regex_replace(basic_string) allocator handling

Section: 28.11.4 [re.alg.replace] Status: New Submitter: Jeffrey Yasskin Opened: 2012-11-26 Last modified: 2013-10-15

View other active issues in [re.alg.replace].

View all other issues in [re.alg.replace].

View all issues with New status.

Discussion:

template <class traits, class charT, class ST, class SA>
  basic_string<charT, ST, SA>
  regex_replace(const basic_string<charT, ST, SA>& s,
      const basic_regex<charT, traits>& e,
      const charT* fmt,
      regex_constants::match_flag_type flags = 
	    regex_constants::match_default);

and friends are documented as

Constructs an empty string result of type basic_string<charT, ST, SA> and calls regex_replace(back_inserter(result), s.begin(), s.end(), e, fmt, flags).

This appears to require the result to have a default-constructed allocator, which isn't even possible for all allocator types. I suspect the allocator should be copied from 's' instead. Possibly there should be an additional defaulted argument to override the allocator of the result.

Proposed resolution:


2217. operator==(sub_match, string) slices on embedded '\0's

Section: 28.9.2 [re.submatch.op] Status: New Submitter: Jeffrey Yasskin Opened: 2012-11-26 Last modified: 2013-11-28

View all other issues in [re.submatch.op].

View all issues with New status.

Discussion:

template <class BiIter, class ST, class SA>
  bool operator==(
    const basic_string<
      typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
    const sub_match<BiIter>& rhs);

is specified as:

Returns: rhs.compare(lhs.c_str()) == 0.

This is odd because sub_match::compare(basic_string) is defined to honor embedded '\0' characters. This could allow a sub_match to == or != a std::string unexpectedly.

[Daniel:]

This wording change was done intentionally as of LWG 1181, but the here mentioned slicing effect was not considered at that time. It seems best to use another overload of compare to fix this problem:

Returns: rhs.str().compare(0, rhs.length(), lhs.data(), lhs.size()) == 0.

or

Returns: rhs.compare(sub_match<BiIter>::string_type(lhs.data(), lhs.size())) == 0.

[2013-10-17: Daniel provides concrete wording]

The original wording was suggested to reduce the need to allocate memory during comparisons. The specification would be very much easier, if sub_match would provide an additional compare overload of the form:

int compare(const value_type* s, size_t n) const;

But given the fact that currently all of basic_string's compare overloads are defined in terms of temporary string constructions, the following proposed wording does follow the same string-construction route as basic_string does (where needed to fix the embedded zeros issue) and to hope that existing implementations ignore to interpret this semantics in the literal sense.

I decided to use the second replacement form

Returns: rhs.compare(sub_match<BiIter>::string_type(lhs.data(), lhs.size())) == 0.

because it already reflects the existing style used in 28.9.2 [re.submatch.op] p31.

Proposed resolution:

This wording is relative to N3691.

  1. Change 28.9.2 [re.submatch.op] as indicated:

    template <class BiIter, class ST, class SA>
      bool operator==(
        const basic_string<
          typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
        const sub_match<BiIter>& rhs);
    

    -7- Returns: rhs.compare(lhs.c_str()typename sub_match<BiIter>::string_type(lhs.data(), lhs.size())) == 0.

    […]

    template <class BiIter, class ST, class SA>
      bool operator<(
        const basic_string<
          typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
        const sub_match<BiIter>& rhs);
    

    -9- Returns: rhs.compare(lhs.c_str()typename sub_match<BiIter>::string_type(lhs.data(), lhs.size())) > 0.

    […]

    template <class BiIter, class ST, class SA>
      bool operator==(const sub_match<BiIter>& lhs,
                      const basic_string<
                        typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
    

    -13- Returns: lhs.compare(rhs.c_str()typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) == 0.

    […]

    template <class BiIter, class ST, class SA>
      bool operator<(const sub_match<BiIter>& lhs,
                     const basic_string<
                       typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
    

    -15- Returns: lhs.compare(rhs.c_str()typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) < 0.


2218. Unclear how containers use allocator_traits::construct()

Section: 23.2.1 [container.requirements.general] Status: Open Submitter: Jonathan Wakely Opened: 2012-11-27 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with Open status.

Discussion:

Firstly, 23.2.1 [container.requirements.general]/7 says a container's allocator is used to obtain memory, but it isn't stated explicitly that the same allocator is used to construct and destroy elements, as opposed to a value-initialized allocator of the same type.

Secondly, 23.2.1 [container.requirements.general]/3 says elements "shall be constructed using the allocator_traits<allocator_type>::construct function and destroyed using the allocator_traits<allocator_type>::destroy function" and 23.2.1 [container.requirements.general]/13 defines CopyInsertable etc. in terms of an allocator A which is identical to the container's allocator_type.

The intent of making construct() and destroy() function templates was that containers would be permitted to use allocator_traits<A>::construct() instead of allocator_traits<allocator_type>::construct(), where A is allocator_traits<allocator_type>::rebind_alloc<U> for some other type U. This allows node-based containers to store an allocator of the right type for allocating nodes and to use the same object to construct elements in aligned storage within those nodes, avoiding rebinding and copying the stored allocator every time an element needs to be constructed.

It should be made clear that a possibly-rebound copy of the container's allocator is used for object construction.

[2013-03-15 Issues Teleconference]

Moved to Open.

Jonathan: point 2 in the proposed resolution is definitely needed.

Proposed resolution:

This wording is relative to N3485.

  1. Edit 23.2.1 [container.requirements.general] paragraph 3:

    For the components affected by this subclause that declare an allocator_type, objects stored in these components shall be constructed using the allocator_traits<allocator_type>::rebind_alloc<U>::construct function and destroyed using the allocator_traits<allocator_type>::rebind_alloc<U>::destroy function (20.7.8.2 [allocator.traits.members]), where U is either allocator_type::value_type or an internal type used by the container. These functions are called only for the container's element type, not for internal types used by the container. [ Note: This means, for example, that a node-based container might need to construct nodes containing aligned buffers and call construct to place the element into the buffer. — end note ]

  2. Edit 23.2.1 [container.requirements.general] paragraph 7:

    […] A copy of this allocator is used for any memory allocation and element construction performed, by these constructors and by all member functions, during the lifetime of each container object or until the allocator is replaced. […]

  3. Edit 23.2.1 [container.requirements.general] paragraph 13:

    […] Given an allocator type A and given a container type X having an allocator_type identical to A and a value_type identical to T and an allocator_type identical to allocator_traits<A>::rebind_alloc<T> and given an lvalue m of type A, a pointer p of type T*, an expression v of type (possibly const) T, and an rvalue rv of type T, the following terms are defined.

    […]

    [ Note: A container calls allocator_traits<A>::construct(m, p, args) to construct an element at p using args, with m == get_allocator(). The default construct in std::allocator will call ::new((void*)p) T(args), but specialized allocators may choose a different definition. — end note ]


2219. INVOKE-ing a pointer to member with a reference_wrapper as the object expression

Section: 20.9.2 [func.require] Status: Open Submitter: Jonathan Wakely Opened: 2012-11-28 Last modified: 2013-10-15

View all other issues in [func.require].

View all issues with Open status.

Discussion:

The standard currently requires this to be invalid:

#include <functional>

struct X { int i; } x;
auto f = &X::i;
auto t1 = std::ref(x);
int i = std::mem_fn(f)(t1);

The call expression on the last line is equivalent to INVOKE(f, std::ref(x)) which according to 20.9.2 [func.require]p1 results in the invalid expression (*t1).*f because reference_wrapper<X> is neither an object of type X nor a reference to an object of type X nor a reference to an object of a type derived from X.

The same argument applies to pointers to member functions, and if they don't work with INVOKE it becomes harder to do all sorts of things such as:

call_once(o, &std::thread::join, std::ref(thr))

or

async(&std::list<int>::sort, std::ref(list));

The definition of INVOKE should be extended to handle reference wrappers.

[2013-03-15 Issues Teleconference]

Moved to Review.

The wording seems accurate, but verbose. If possible, we would like to define the kind of thing being specified so carefully as one of a number of potential language constructs in a single place. It is also possible that this clause is that single place.

[2013-04-18, Bristol]

Jonathan comments:

In the proposed resolution in the first bullet (t1.*f) is not valid if t1 is a reference_wrapper, so we probably need a separate bullet to handle the reference_wrapper case.

Proposed resolution:

This wording is relative to N3485.

  1. Edit 20.9.2 [func.require]:

    Define INVOKE(f, t1, t2, ..., tN) as follows:

    • (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T U or an object of type reference_wrapper<U> or a reference to an object of type reference_wrapper<U> where U is either the type T or a type derived from T;

    • ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is not one of the types described in the previous item;

    • t1.*f when N == 1 and f is a pointer to member data of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T U or an object of type reference_wrapper<U> or a reference to an object of type reference_wrapper<U> where U is either the type T or a type derived from T;

    • (*t1).*f when N == 1 and f is a pointer to member data of a class T and t1 is not one of the types described in the previous item;

    • f(t1, t2, ..., tN) in all other cases.


2220. Under-specification of operator== for regex_token_iterator

Section: 28.12.2.2 [re.tokiter.comp] Status: New Submitter: Pete Becker Opened: 2012-11-21 Last modified: 2013-10-15

View other active issues in [re.tokiter.comp].

View all other issues in [re.tokiter.comp].

View all issues with New status.

Discussion:

Consider the following example:

std::string str0("x");
std::regex rg0("a");
std::regex_token_iterator it0(str0.begin(), str0.end(), rg0, -1); // points at "x" in str0
std::string str1("x");
std::regex rg1("b");
std::regex_token_iterator it1(str1.begin(), str1.end(), rg1, -1); // points at "x" in str1

28.12.2.2 [re.tokiter.comp] p1 says that it0.operator==(it1) returns true "if *this and right are both suffix iterators and suffix == right.suffix"; both conditions are satisfied in this example. It does not say that they must both be iterators into the same sequence, nor does it say (as general iterator requirements do) that they must both be in the domain of == in order for the comparison to be meaningful. It's a simple statement: they're equal if the strings they point at compare equal. Given this being a valid comparison, the obtained result of "true" looks odd.

The problem is that for iterator values prior to the suffix iterator, equality means the same regular expression and the same matched sequence (both uses of "same" refer to identity, not equality); for the suffix iterator, equality means that the matched sequences compare equal.

Proposed resolution:


2221. No formatted output operator for nullptr

Section: 28.12.2.2 [re.tokiter.comp] Status: New Submitter: Matt Austern Opened: 2012-12-07 Last modified: 2013-10-15

View other active issues in [re.tokiter.comp].

View all other issues in [re.tokiter.comp].

View all issues with New status.

Discussion:

When I write

std::cout << nullptr << std::endl;

I get a compilation error, "ambiguous overload for 'operator<<' in 'std::cout << nullptr'". As far as I can tell, the compiler is right to issue that error. There are inserters for const void*, const char*, const signed char*, and const unsigned char*, and none for nullptr_t, so the expression really is ambiguous.

Proposed resolution:

The obvious library solution is to add a nullptr_t overload, which would be defined something like

template<class C, class T>
basic_ostream<C, T>& operator<<(basic_ostream<C, T>& os, nullptr_t) 
{ 
  return os << (void*) nullptr; 
}

We might also consider addressing this at a core level: add a special-case language rule that addresses all cases where you write f(nullptr) and f is overloaded on multiple pointer types. (Perhaps a tiebreaker saying that void* is preferred in such cases.)

Proposed resolution:


2223. shrink_to_fit effect on iterator validity

Section: 23.3.6.3 [vector.capacity] Status: Open Submitter: Juan Soulie Opened: 2012-12-17 Last modified: 2013-10-15

View other active issues in [vector.capacity].

View all other issues in [vector.capacity].

View all issues with Open status.

Discussion:

After the additions by 2033, it appears clear that the intended effect includes a reallocation and thus the potential effect on iterators should be explicitly added to the text in order to not contradict 23.2.1 [container.requirements.general]/11, or at the very least, explicitly state that a reallocation may happen.

Taking consistency with "reserve" into consideration, I propose:

BTW, while we are at it, I believe the effect on iterators should also be explicitly stated in the other instance a reallocation may happen: 23.3.6.5 [vector.modifiers]/1 — even if obvious, it only contradicts 23.2.1 [container.requirements.general]/11 implicitly.

I propose to also insert "Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence." at the appropriate location in its "Remarks".

[2012-12-19: Jonathan Wakely comments]

The described problem also affects std::basic_string and std::deque.

[2013-03-15 Issues Teleconference]

Moved to Review.

[2013-04-18, Bristol]

Daniel extends the P/R.

Rationale:

The wording in 21.4.4 [string.capacity] combined with 21.4.1 [string.require] seems to say the necessary things. We cannot impose all requirements as we do for vector, because we want to allow the short-string-optimization.

Proposed resolution:

This wording is relative to N3485.

  1. Keep 21.4.4 [string.capacity] around p14 unchanged, because we don't speak about reallocations and we give the strong exception guarantee in 21.4.1 [string.require] (Invalidation specification also at that place):

    void shrink_to_fit();
    

    -14- Remarks: shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations. — end note ].

  2. Edit 23.3.3.3 [deque.capacity] around p7 as indicated:

    void shrink_to_fit();
    

    -5- Requires: T shall be MoveInsertable into *this.

    -?- Effects: shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations. — end note ] Reallocation happens at this point if and only if the function effectively reduces the capacity. If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.

    -6- Complexity: Linear in the size of the sequence.

    -7- Remarks: shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations. — end note ] If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence.

  3. Edit 23.3.6.3 [vector.capacity] around p7 as indicated:

    void shrink_to_fit();
    

    -7- Requires: T shall be MoveInsertable into *this.

    -?- Effects: shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations. — end note ] Reallocation happens at this point if and only if the function effectively reduces the capacity. If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.

    -8- Complexity: Linear in the size of the sequence.

    -9- Remarks: shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations. — end note ] If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence.

  4. Edit 23.3.6.5 [vector.modifiers] p1 as indicated:

    iterator insert(const_iterator position, const T& x);
    iterator insert(const_iterator position, T&& x);
    iterator insert(const_iterator position, size_type n, const T& x);
    template <class InputIterator>
    iterator insert(const_iterator position, InputIterator first, InputIterator last);
    iterator insert(const_iterator position, initializer_list<T>);
    template <class... Args> void emplace_back(Args&&... args);
    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
    void push_back(const T& x);
    void push_back(T&& x);
    

    -1- Remarks: Causes reallocation if the new size is greater than the old capacity. Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence. If no reallocation happens, all the iterators and references before the insertion point remain valid. If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of T or by any InputIterator operation there are no effects. If an exception is thrown by the move constructor of a non-CopyInsertable T, the effects are unspecified.


2224. Ambiguous status of access to non-live objects

Section: 17.6.4.10 [res.on.objects] Status: Open Submitter: Geoffrey Romer Opened: 2012-12-17 Last modified: 2013-10-15

View all other issues in [res.on.objects].

View all issues with Open status.

Discussion:

The standard currently does not discuss when library objects may be accessed, except in a non-normative note pertaining to synchronization in [res.on.objects], leaving it ambiguous whether single-threaded code can access a library object during its construction or destruction. For example, there is a reasonable question as to what happens if the deleter supplied to a unique_ptr transitively accesses the unique_ptr itself during unique_ptr's destruction; a straightforward reading suggests that this is permitted, and that the deleter will see the unique_ptr still holding the originally stored pointer, but consensus on the LWG reflector indicates this was not the intent (see discussion beginning with c++std-lib-33362).

[2013-03-15 Issues Teleconference]

Moved to Open.

Geoffrey will provide an example that clearly highlights the issue.

[2013-03-19 Geoffrey provides revised resolution and an example]

I contend that the most straightforward reading of the current standard requires the following example code to print "good" (because ~unique_ptr is not specified to modify the state of the internal pointer), but the consensus on the reflector was that its behavior should be undefined.

This example also shows that, contrary to a comment in the telecon, the PR is not tautological. 12.7 [class.cdtor]/p4 explicitly permits member function calls during destruction, so the behavior of this code is well-defined as far as the core language is concerned, despite the fact that it accesses a library object after the end of the object's lifetime. If we want this code to have undefined behavior, we need to specify that at the library level.

#include <memory>
#include <iostream>

class A;

struct B {
 std::unique_ptr<A> a;
};

struct A {
 B* b;
 ~A() {
   if (b->a.get() == this) {
     std::cout << "good" << std::endl;
   }
 }
};

int main() {
 B b;
 b.a.reset(new A);
 b.a->b = &b;
}

Previous resolution:

  1. Change the title of sub-clause 17.6.4.10 [res.on.objects] as indicated:

    Shared objects and the libraryLibrary object access [res.on.objects]

  2. Edit 17.6.4.10 [res.on.objects] p2 as indicated:

    -2- [Note: In particular, the program is required to ensure that completion of the constructor of any object of a class type defined in the standard library happens before any other member function invocation on that object and, unless otherwise specified, to ensure that completion of any member function invocation other than destruction on such an object happens before destruction of that object. This applies even to objects such as mutexes intended for thread synchronization. — end note] If an object of a standard library type is accessed outside of the object's lifetime (3.8 [basic.life]), the behavior is undefined unless otherwise specified.

Proposed resolution:

This wording is relative to N3485.

  1. Change the title of sub-clause 17.6.4.10 [res.on.objects] as indicated:

    Shared objects and the libraryLibrary object access [res.on.objects]

  2. Edit 17.6.4.10 [res.on.objects] p2 as indicated: [Editorial remark: The motivation, is to be more precise about the meaning of "outside the object's lifetime" in the presence of threads — end editorial remark]

    -2- [Note: In particular, the program is required to ensure that completion of the constructor of any object of a class type defined in the standard library happens before any other member function invocation on that object and, unless otherwise specified, to ensure that completion of any member function invocation other than destruction on such an object happens before destruction of that object. This applies even to objects such as mutexes intended for thread synchronization. — end note] If an object of a standard library type is accessed, and the beginning of the object's lifetime (3.8 [basic.life]) does not happen before the access, or the access does not happen before the end of the object's lifetime, the behavior is undefined unless otherwise specified.


2227. Stateful comparison objects in associative containers

Section: 23.2.4 [associative.reqmts] Status: Open Submitter: Juan Soulie Opened: 2012-12-19 Last modified: 2013-10-15

View other active issues in [associative.reqmts].

View all other issues in [associative.reqmts].

View all issues with Open status.

Discussion:

Table 102 in 23.2.4 [associative.reqmts]/8 states on expression a.key_comp() that it "returns the comparison object out of which a was constructed". At the same time, 23.2.1 [container.requirements.general]/8 states (starting in the third line) that "...Any Compare, Pred, or Hash objects belonging to a and b shall be swappable and shall be exchanged by unqualified calls to non-member swap...". This is problematic for any compliant implementation, since once swapped the container cannot return the comparison object out of which it was constructed unless incurring in storing an otherwise needless object.

The simple solution is to correct that statement in Table 102, but I believe this is part of a larger problem of underspecified behavior: The new standard has made an effort in regards to allocators and now fully specifies what happens to stateful allocator objects. It has even specified what happens to stateful hasher and key_equal members of unordered containers (they propagate), but it says nothing about stateful comparison objects of (ordered) associative containers, except for the statement in 23.2.1 [container.requirements.general]/8 referred above and only related to swap.

For example, it is unclear to me what is specified to happen on an assignment: should the comparison object be copied/moved along with the elements, or should the left-hand side object keep its own? Maybe this has been intentionally left unspecified with the purpose of compatibility with C++98, which I understand it specified that comparison objects were kept for the entire life of the container (like allocators) — an unfortunate choice. But anyway, the segment of 23.2.1 [container.requirements.general] quoted above seems to break any possible backwards compatibility with C++98 in this regard.

Therefore, taking into consideration consistency with how this is dealed with for unordered associative containers, I propose that Table 102 is modified as follows:

[2013-03-15 Issues Teleconference]

Moved to Review.

[2013-04-18, Bristol]

STL: can't believe we don't specify this already. this is totally necessary

Alisdair: how does it do this? copy construction? assignment?

ALso need it for move.

STL: we already specify this for constructing from a comparator, not during copy construction though.

Jonathan: don't like wording, should say "key_compare is CopyConstructible. Uses b.key_comp() as a comparison object."

STL: we get it right for unordered!

Jonathan: can't wordsmith this now, but I think implementations do the right thing.

Alisdair: not sure what right thing is for moves. also we say nothing about propagating allocators to functors.

Moved to Open.

Proposed resolution:

This wording is relative to N3485.

  1. Change Table 102 as indicated:

    Table 102 — Associative container requirements (in addition to container)
    Expression Return type Assertion/note pre-/post-condition Complexity
    X(il) Same as X(il.begin(), il.end()). same as X(il.begin(), il.end()).
    X(b)
    X a(b)
    Copy constructor. In addition to
    the requirements of Table 96, copies
    the comparison object.
    Linear in b.size()
    a = b X& Copy assignment operator. In addition to
    the requirements of Table 96, copies the
    comparison object.
    Linear in a.size() and b.size()
    a.key_comp() X::key_compare rReturns thea's comparison object
    out of which a was constructed.
    constant

2228. Missing SFINAE rule in unique_ptr templated assignment

Section: 20.8.1.2.3 [unique.ptr.single.asgn] Status: Review Submitter: Geoffrey Romer Opened: 2012-12-20 Last modified: 2013-10-15

View all other issues in [unique.ptr.single.asgn].

View all issues with Review status.

Discussion:

20.8.1.2.3 [unique.ptr.single.asgn]/5 permits unique_ptr's templated assignment operator to participate in overload resolution even when incompatibilities between D and E will render the result ill-formed, but the corresponding templated copy constructor is removed from the overload set in those situations (see the third bullet point of 20.8.1.2.1 [unique.ptr.single.ctor]/19). This asymmetry is confusing, and presumably unintended; it may lead to situations where constructing one unique_ptr from another is well-formed, but assigning from the same unique_ptr would be ill-formed.

There is a slight coupling between this and LWG 2118, in that my PR for LWG 2118 incorporates equivalent wording in the specification of the templated assignment operator for the array specialization; the two PRs are logically independent, but if my PR for 2118 is accepted but the above PR is not, the discrepancy between the base template and the specialization could be confusing.

[2013-03-15 Issues Teleconference]

Moved to Review.

The wording looks good, but we want a little more time than the telecon permits to be truly comfortable. We expect this issue to resolve fairly easily in Bristol.

Proposed resolution:

This wording is relative to N3485.

  1. Revise 20.8.1.2.3 [unique.ptr.single.asgn] p5 as follows:

    template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
    

    -4- Requires: If E is not a reference type, assignment of the deleter from an rvalue of type E shall be well-formed and shall not throw an exception. Otherwise, E is a reference type and assignment of the deleter from an lvalue of type E shall be well-formed and shall not throw an exception.

    -5- Remarks: This operator shall not participate in overload resolution unless:

    • unique_ptr<U, E>::pointer is implicitly convertible to pointer and

    • U is not an array type., and

    • either D is a reference type and E is the same type as D, or D is not a reference type and E is implicitly convertible to D.

    -6- Effects: Transfers ownership from u to *this as if by calling reset(u.release()) followed by an assignment from std::forward<E>(u.get_deleter()).

    -7- Returns: *this.


2230. "see below" for initializer-list constructors of unordered containers

Section: 23.5 [unord] Status: Deferred Submitter: Jonathan Wakely Opened: 2013-01-06 Last modified: 2014-01-20

View all other issues in [unord].

View all issues with Deferred status.

Discussion:

The unordered_map class definition in 23.5.4.1 [unord.map.overview] declares an initializer-list constructor that says "see below":

unordered_map(initializer_list<value_type>,
    size_type = see below,
    const hasher& hf = hasher(),
    const key_equal& eql = key_equal(),
    const allocator_type& a = allocator_type());

But that constructor isn't defined below. The same problem exists for the other unordered associative containers.

[2013-09 Chicago]

STL: ordered are also missing declarations, but issue is forthcoming

Walter: how does adding a signature address issue? — nevermind

Jayson: in his wording, isn't he just dropping the size_type?

Walter: partial fix is to introduce the name

Stefanus: explanation of requiring name because of n buckets

STL: solution for his issue satisfies both ordered and unordered and is simplier than provided wording

STL: patches general table instead

STL: proposes adding extra rows instead of extra declarations

Stefanus: clarify n in the synopsis

Walter: general rule, name is optional in declaration

Stefanus: how to proceed

Walter: significant overlap with forthcoming issue, suggestion to defer

Proposed resolution:

This wording is relative to N3485.

  1. Edit 23.5.4.2 [unord.map.cnstr] as follows:

    template <class InputIterator>
    unordered_map(InputIterator f, InputIterator l,
      size_type n = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    unordered_map(initializer_list<value_type> il,
      size_type = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    

    -3- Effects: Constructs an empty unordered_map using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is implementation-defined. Then inserts elements from the range [f, l) for the first form, or from the range [il.begin(), il.end()) for the second form. max_load_factor() returns 1.0.

  2. Edit 23.5.5.2 [unord.multimap.cnstr] as follows:

    template <class InputIterator>
    unordered_multimap(InputIterator f, InputIterator l,
      size_type n = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    unordered_multimap(initializer_list<value_type> il,
      size_type = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    

    -3- Effects: Constructs an empty unordered_multimap using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is implementation-defined. Then inserts elements from the range [f, l) for the first form, or from the range [il.begin(), il.end()) for the second form. max_load_factor() returns 1.0.

  3. Edit 23.5.6.2 [unord.set.cnstr] as follows:

    template <class InputIterator>
    unordered_set(InputIterator f, InputIterator l,
      size_type n = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    unordered_set(initializer_list<value_type> il,
      size_type = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    

    -3- Effects: Constructs an empty unordered_set using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is implementation-defined. Then inserts elements from the range [f, l) for the first form, or from the range [il.begin(), il.end()) for the second form. max_load_factor() returns 1.0.

  4. Edit 23.5.7.2 [unord.multiset.cnstr] as follows:

    template <class InputIterator>
    unordered_multiset(InputIterator f, InputIterator l,
      size_type n = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    unordered_multiset(initializer_list<value_type> il,
      size_type = see below,
      const hasher& hf = hasher(),
      const key_equal& eql = key_equal(),
      const allocator_type& a = allocator_type());
    

    -3- Effects: Constructs an empty unordered_multiset using the specified hash function, key equality function, and allocator, and using at least n buckets. If n is not provided, the number of buckets is implementation-defined. Then inserts elements from the range [f, l) for the first form, or from the range [il.begin(), il.end()) for the second form. max_load_factor() returns 1.0.


2233. bad_function_call::what() unhelpful

Section: 20.9.11.1 [func.wrap.badcall] Status: Open Submitter: Jonathan Wakely Opened: 2013-01-05 Last modified: 2013-10-15

View all issues with Open status.

Discussion:

A strict reading of the standard implies std::bad_function_call{}.what() returns the same string as std::exception{}.what() which doesn't help to know what happened if you catch an exception by reference to std::exception.

For consistency with bad_weak_ptr::what() it should return "bad_function_call".

See c++std-lib-33515 for other details.

There was a considerable support on the reflector to instead change the specification of both bad_weak_ptr::what() and bad_function_call::what() to return an implementation-defined string instead.

[2013-03-15 Issues Teleconference]

Moved to Open.

Consensus that we want consistency in how this is treated. Less consensus on what the common direction should be.

Alisdair to provide wording proposing that all string literals held by standard exception objects are either unspecified, or implmentation defined.

Proposed resolution:

This wording is relative to N3485.

  1. Edit 20.9.11.1.1 [func.wrap.badcall.const]:

    bad_function_call() noexcept;
    

    -1- Effects: constructs a bad_function_call object.

    -?- Postconditions: what() returns "bad_function_call".


2234. assert() should allow usage in constant expressions

Section: 19.3 [assertions] Status: Open Submitter: Daniel Krügler Opened: 2013-01-12 Last modified: 2013-10-15

View all issues with Open status.

Discussion:

It is unclear from the current specification whether assert() expressions can be used in (potential) constant expressions. As an example consider the implementation of a constexpr function:

#include <cassert>

template<class T, unsigned N>
struct array {
  T data[N];
  constexpr const T& operator[](unsigned i) const {
    return assert(i < N), data[i];
  }
};

int main() {
  constexpr array<int, 3> ai = {1, 2, 3};
  constexpr int i = ai[0];
  int j = ai[0];
  // constexpr int k = ai[5];
}

The first question is whether this program is guaranteed well-formed? A second question is whether is would guaranteed to be ill-formed, if we uncomment the last code line in main()?

The wording in 19.3 [assertions] doesn't add anything significant to the C99 wording. From the C99 specification (7.2 p1 and 7.2.1.1 p2) we get already some valuable guarantees:

The current wording does not yet guarantee that assert expressions can be used in constant expressions, but all tested implementations (gcc, MSVC) would already support this use-case. It seems to me that this should be possible without giving assert a special meaning for the core language.

As a related comment it should be added, that there is a core language proposal that intents to relax some current constraints for constexpr functions and literal types. The most interessting one (making void a literal types and allowing for expression-statements) would simplify the motivating example implementation of operator[] to:

constexpr const T& operator[](unsigned i) const {
  assert(i < N);
  return data[i];
};

[2013-03-15 Issues Teleconference]

Moved to Open.

We are still gaining experience with constexpr as a language feature, and there may be work in Evolution that would help address some of these concerns. Defer discussion until we have a group familiar with any evolutionary direction.

Proposed resolution:


2236. kill_dependency unconditionally noexcept

Section: 29.2 [atomics.syn], 29.3 [atomics.order] Status: New Submitter: Daniel Krügler Opened: 2013-01-19 Last modified: 2013-10-15

View all other issues in [atomics.syn].

View all issues with New status.

Discussion:

The "magic" kill_dependency function is a function without any constraints on the template parameter T and is specified as

template <class T>
T kill_dependency(T y) noexcept;

-14- Effects: The argument does not carry a dependency to the return value (1.10).

-15- Returns: y.

I wonder whether the unconditional noexcept is really intended here: Assume we have some type U that has a potentially throwing move constructor (or it has a potentially throwing copy constructor and no move constructor), for any "normal" function template with the same signature and the same effects (modulo the dependency magic) this would mean that it cannot safely be declared noexcept because of the return statement being part of the complete function call affected by noexcept (The by-value function argument is irrelevant in this context). In other words it seems that a function call such as

struct S {
  ...
  S(const S& r) { if(some condition) throw Something(); }
  ...
};

int main() {
  S s1 = ...;
  S s2 = std::kill_dependency(s1);
}

would be required to call std::terminate if the copy constructor of S throws during the return of std::kill_dependency.

To require copy elision for this already magic function would look like a low-hanging fruit to solve this problem, but this case is not covered by current copy elision rules see 12.8 p31 b1:

"— in a return statement in a function with a class return type, when the expression is the name of a non-volatile automatic object (other than a function or catch-clause parameter) with the same cv-unqualified type as the function return type, the copy/move operation can be omitted by constructing the automatic object directly into the function's return value".

Some options come into my mind:

  1. Make the exception-specification a constrained one in regard via std::is_nothrow_move_constructible:

    template <class T>
    T kill_dependency(T y) noexcept(see below);
    

    This is similar to the approach taken for function templates such as std::swap.

  2. Use perfect forwarding (This needs further wording to correct the effects):

    template <class T>
    T&& kill_dependency(T&& y) noexcept;
    
  3. Impose constraints on the template arguments in regard to throwing exceptions while copying/moving.

  4. Keep the state as it is but possibly add a note about a call of std::terminate in above scenario.

A second problem is that the current wording is not clear whether it is well-defined to call the function with types that are reference types, such as in the following example:

#include <atomic>

int main()
{
  int a = 12;
  int& b = std::kill_dependency<int&>(a);
}

It is unclear what kind of dependency is killed here. This is presumably a core language problem, but could affect the possible resolutions of the problem.

Proposed resolution:


2237. <cuchar> macros

Section: 21.8 [c.strings] Status: New Submitter: Jason Merrill Opened: 2013-01-29 Last modified: 2013-10-15

View other active issues in [c.strings].

View all other issues in [c.strings].

View all issues with New status.

Discussion:

Apparently C1X changes __STDC_UTF_16__ and __STDC_UTF_32__ from macros defined in uchar.h (and reflected in C++ by Table 79) to be predefined by the compiler. Do we want to do the same?

Proposed resolution:


2238. Problematic iterator-pair constructor of containers

Section: 21.8 [c.strings] Status: New Submitter: Johannes Schaub Opened: 2013-02-02 Last modified: 2013-10-15

View other active issues in [c.strings].

View all other issues in [c.strings].

View all issues with New status.

Discussion:

The non-explicit nature of the iterator-pair constructor of containers, such a

template <class InputIterator>
vector(InputIterator first, InputIterator last, const Allocator& = Allocator());

can be selected in unexpected situations, leading to a hard runtime error, as demonstrated by the following example:

#include <vector>

void f(std::vector<char> v){ /* ... */}

int main() {
  f({"A", "B"});
}

The actually intended initializer-list constructor isn't feasible here, so the best match is the constructor template

template <class InputIterator>
vector(InputIterator first, InputIterator last, const Allocator& = Allocator());

This compiles, but will result in code running amok. The potential trap (that cannot be easily detected by the library implementation) could be reduced by making this constructor explicit. It would still have the effect to be selected here, but the code would be ill-formed, so the programmer gets a clear meassage here.

Proposed resolution:


2239. min/max/minmax requirements

Section: 25.4.7 [alg.min.max] Status: New Submitter: Juan Soulie Opened: 2013-01-26 Last modified: 2013-10-15

View other active issues in [alg.min.max].

View all other issues in [alg.min.max].

View all issues with New status.

Discussion:

25.4.7 [alg.min.max] requires type T in min, max, and minmax to be LessThanComparable, but I don't believe this should be required for the versions that take a Compare argument.

Paragraphs 1 to 4 of 25.4 [alg.sorting] should apply anyway, although I'm not sure about Compare being required to induce a strict weak ordering here.

Further, min and max also lack formal complexity guarantees.

Proposed resolution:


2240. Probable misuse of term "function scope" in [thread.condition]

Section: 30.5.1 [thread.condition.condvar], 30.5.2 [thread.condition.condvarany] Status: Ready Submitter: FrankHB1989 Opened: 2013-02-03 Last modified: 2013-10-15

View other active issues in [thread.condition.condvar].

View all other issues in [thread.condition.condvar].

View all issues with Ready status.

Discussion:

All usages of "function scope" in 30.5.1 [thread.condition.condvar] and 30.5.2 [thread.condition.condvarany], such as 30.5.1 [thread.condition.condvar] p10 b4:

If the function exits via an exception, lock.lock() shall be called prior to exiting the function scope.

seem to be inappropriate compared to the actual core language definition of 3.3.5 [basic.funscope]:

Labels (6.1) have function scope and may be used anywhere in the function in which they are declared. Only labels have function scope.

Probably the intended meaning is "outermost block scope of the function".

[2013-09 Chicago: Resolved by proposed resolution of LWG 2135]

Proposed resolution:

Resolved by proposed resolution of LWG 2135.


2241. <cstdalign> and #define of alignof

Section: 18.10 [support.runtime] Status: New Submitter: Richard Smith Opened: 2013-02-14 Last modified: 2013-10-15

View other active issues in [support.runtime].

View all other issues in [support.runtime].

View all issues with New status.

Discussion:

According to 18.10 [support.runtime] p2:

The contents of these headers are the same as the Standard C library headers [..], <stdalign.h>, [..]

Since our base C standard is C99, which doesn't have a <stdalign.h>, the reference to a non-existing C header is irritating (In this context <stdalign.h> doesn't refer to the deprecated C++ header <stdalign.h> described in D.5 [depr.c.headers]).

Furthermore, it would be also important that it doesn not define a macro named alignof, which C11 also defines in this header.

Currently we only have the following guarantee as part of 18.10 [support.runtime] p7:

The header <cstdalign> and the header <stdalign.h> shall not define a macro named alignas.

It is unclear what the better strategy is: Striking the reference to <stdalign.h> in 18.10 [support.runtime] p2 or upgrading to C11 as new base C standard.

Proposed resolution:


2242. [uninitialized_]copy_n() defect

Section: 25.3.1 [alg.copy], 20.7.12.2 [uninitialized.copy] Status: New Submitter: Sean Parent Opened: 2013-02-14 Last modified: 2013-10-15

View all other issues in [alg.copy].

View all issues with New status.

Discussion:

copy_n() and uninitialized_copy_n() only return the output iterator, and not the input iterator. Likely the interface was simply copied from the original STL. Unfortunately the interface in the original STL contains a bug.

copy_n() and uninitialized_copy_n() must return the resulting input iterator as well as the output iterator (I would suggest returning a pair). Without this, there is no way to continue reading from an actual input iterator — and if it is really a forward iterator, it will cost n increments to get back to where you were.

Proposed resolution:


2243. istream::putback problem

Section: 27.7.2.3 [istream.unformatted] Status: New Submitter: Juan Soulie Opened: 2013-03-01 Last modified: 2013-10-15

View other active issues in [istream.unformatted].

View all other issues in [istream.unformatted].

View all issues with New status.

Discussion:

In 27.7.2.3 [istream.unformatted] / 34, when describing putback, it says that "rdbuf->sputbackc()" is called. The problem are not the obvious typos in the expression, but the fact that it may lead to different interpretations, since nowhere is specified what the required argument to sputbackc is.

It can be guessed to be "rdbuf()->sputbackc(c)", but "rdbuf()->sputbackc(char_type())" or just anything would be as conforming (or non-confoming) as the first guess.

Proposed resolution:


2244. Issue on basic_istream::seekg

Section: 27.7.2.3 [istream.unformatted] Status: New Submitter: Juan Soulie Opened: 2013-03-04 Last modified: 2013-11-28

View other active issues in [istream.unformatted].

View all other issues in [istream.unformatted].

View all issues with New status.

Discussion:

When issue 1445 was resolved by adopting N3168, it exposed the need to modify both overloads of basic_istream::seekg (by inserting "the function clears eofbit," after "except that"), but the fix applied to the text apparently forgets the second overload at 27.7.2.3 [istream.unformatted] p43.

[2013-10-17: Daniel provides concrete wording]

It seems that the tiny sentence "SIMILARLY for 27.7.1.3/43 (seekg)." had been overlooked. I agree that the wording needs to be applied here as well.

Proposed resolution:

This wording is relative to N3691.

  1. Change 27.7.2.3 [istream.unformatted] p43 as indicated:

    basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir);
    

    -43- Effects: Behaves as an unformatted input function (as described in 27.7.2.3, paragraph 1), except that the function first clears eofbit, it does not count the number of characters extracted, and does not affect the value returned by subsequent calls to gcount(). […]


2245. packaged_task::reset() memory allocation

Section: 27.7.2.3 [istream.unformatted] Status: New Submitter: Jonathan Wakely Opened: 2013-03-05 Last modified: 2013-10-15

View other active issues in [istream.unformatted].

View all other issues in [istream.unformatted].

View all issues with New status.

Discussion:

The effects of packaged_task::reset() result in memory allocation, but don't allow a user to provide an allocator.

packaged_task::reset() needs to be overloaded like so:

template<class Alloc>  
void reset(const Alloc&);

Alternatively, the effects of reset() need to require the same allocator is used as at construction, which would require the constructor to store the allocator for later use.

I like to remark that GCC at the moment uses the second option, i.e. the allocator passed to the constructor (if any) is used to create the new shared state, because this didn't require any change to the interface.

Proposed resolution:


2248. numeric_limits::is_iec559 misnamed

Section: 18.3.2 [limits] Status: New Submitter: Pete Becker Opened: 2013-03-08 Last modified: 2013-10-15

View all other issues in [limits].

View all issues with New status.

Discussion:

This member should probably be named "is_ieee754". Or at least the standard should explain that IEC-559 no longer exists, and that it's been superseded by IEEE-754.

Proposed resolution:


2250. Follow-up On Library Issue 2207

Section: 20.6.1 [bitset.cons], 20.6.2 [bitset.members], 21.4.2 [string.cons], 21.4.6 [string.modifiers], 21.4.7 [string.ops] Status: New Submitter: Frank Birbacher Opened: 2013-04-18 Last modified: 2013-11-28

View all other issues in [bitset.cons].

View all issues with New status.

Discussion:

Similar to LWG 2207 there are several other places where the “Requires” clause precludes the “Throws” condition. Searching for the out_of_range exception to be thrown, the following have been found (based on the working draft N3485):

  1. 20.6.1 [bitset.cons] p3+4

  2. 20.6.2 [bitset.members] p13+14 (set)

  3. 20.6.2 [bitset.members] p19+20 (reset)

  4. 20.6.2 [bitset.members] p27+28 (flip)

  5. 20.6.2 [bitset.members] p41+42 (test)

  6. 21.4.2 [string.cons] p3+4

  7. 21.4.6.2 [string::append] p3+4

  8. 21.4.6.3 [string::assign] p4+5

  9. 21.4.6.4 [string::insert] p1+2, p5+6, p9+10 (partially)

  10. 21.4.6.5 [string::erase] p1+2

  11. 21.4.6.6 [string::replace] p1+2, p5+6, p9+10 (partially)

  12. 21.4.6.7 [string::copy] p1+2

  13. 21.4.7.8 [string::substr] p1+2

[2013-10-15: Daniel provides wording]

In addition to the examples mentioned in the discussion, a similar defect exists for thread's join() and detach functions (see 30.3.1.5 [thread.thread.member]). The suggested wording applies a similar fix for these as well.

Proposed resolution:

This wording is relative to N3691.

  1. Modify 20.6.1 [bitset.cons] as indicated: [Editorial comment: The wording form used to ammend the Throws element is borrowed from a similar style used in 21.4.6.6 [string::replace] p10]

    template <class charT, class traits, class Allocator>
    explicit
    bitset(const basic_string<charT, traits, Allocator>& str,
           typename basic_string<charT, traits, Allocator>::size_type pos = 0,
           typename basic_string<charT, traits, Allocator>::size_type n =
             basic_string<charT, traits, Allocator>::npos,
             charT zero = charT('0'), charT one = charT('1'));
    

    -3- Requires: pos <= str.size().

    -4- Throws: out_of_range if pos > str.size() or invalid_argument if an invalid character is found (see below).

    -5- Effects: Determines the effective length rlen of the initializing string as the smaller of n and str.size() - pos.

    The function then throws invalid_argument if any of the rlen characters in str beginning at position pos is other than zero or one. The function uses traits::eq() to compare the character values.

    […]

  2. Modify 20.6.2 [bitset.members] as indicated:

    bitset<N>& set(size_t pos, bool val = true);
    

    -13- Requires: pos is valid

    -14- Throws: out_of_range if pos does not correspond to a valid bit position.

    […]

    bitset<N>& reset(size_t pos);
    

    -19- Requires: pos is valid

    -20- Throws: out_of_range if pos does not correspond to a valid bit position.

    […]

    bitset<N>& flip(size_t pos);
    

    -27- Requires: pos is valid

    -28- Throws: out_of_range if pos does not correspond to a valid bit position.

    […]

    bool test(size_t pos) const;
    

    -41- Requires: pos is valid

    -42- Throws: out_of_range if pos does not correspond to a valid bit position.

    […]

  3. Modify 21.4.2 [string.cons] as indicated:

    basic_string(const basic_string& str,
                 size_type pos, size_type n = npos,
                 const Allocator& a = Allocator());
    

    -3- Requires: pos <= str.size()

    -4- Throws: out_of_range if pos > str.size().

  4. Modify 21.4.4 [string.capacity] as indicated:

    void resize(size_type n, charT c);
    

    -6- Requires: n <= max_size()

    -7- Throws: length_error if n > max_size().

  5. Modify 21.4.6.2 [string::append] as indicated:

    basic_string&
      append(const basic_string& str, size_type pos, size_type n);
    

    -3- Requires: pos <= str.size()

    -4- Throws: out_of_range if pos > str.size().

  6. Modify 21.4.6.3 [string::assign] as indicated:

    basic_string&
      assign(const basic_string& str, size_type pos, size_type n);
    

    -4- Requires: pos <= str.size()

    -5- Throws: out_of_range if pos > str.size().

  7. Modify 21.4.6.4 [string::insert] as indicated: [Editorial note: The first change suggestion is also a bug fix of the current wording, because (a) the function has parameter pos1 but the semantics refers to pos and (b) it is possible that this function can throw length_error, see p10]

    basic_string&
      insert(size_type pos1, const basic_string& str);
    

    -1- Requires: pos <= size().

    -2- Throws: out_of_range if pos > size().

    -3- Effects: CallsEquivalent to: return insert(pos, str.data(), str.size());.

    -4- Returns: *this.

    basic_string&
      insert(size_type pos1, const basic_string& str,
             size_type pos2, size_type n);
    

    -5- Requires: pos1 <= size() and pos2 <= str.size().

    -6- Throws: out_of_range if pos1 > size() or pos2 > str.size().

    […]

    basic_string&
      insert(size_type pos, const charT* s, size_type n);
    

    -9- Requires: s points to an array of at least n elements of charT and pos <= size().

    -10- Throws: out_of_range if pos > size() or length_error if size() + n > max_size().

    […]

    basic_string&
      insert(size_type pos, const charT* s);
    

    -13- Requires: pos <= size() and s points to an array of at least traits::length(s) + 1 elements of charT.

    -14- Effects: Equivalent to return insert(pos, s, traits::length(s));.

    -15- Returns: *this.

  8. Modify 21.4.6.5 [string::erase] as indicated:

    basic_string& erase(size_type pos = 0, size_type n = npos);
    

    -1- Requires: pos <= size()

    -2- Throws: out_of_range if pos > size().

    […]

  9. Modify 21.4.6.6 [string::replace] as indicated: [Editorial note: The first change suggestion is also a bug fix of the current wording, because it is possible that this function can throw length_error, see p10]

    basic_string&
      replace(size_type pos1, size_type n1,
              const basic_string& str);
    

    -1- Requires: pos1 <= size().

    -2- Throws: out_of_range if pos1 > size().

    -3- Effects: CallsEquivalent to return replace(pos1, n1, str.data(), str.size());.

    -4- Returns: *this.

    basic_string&
      replace(size_type pos1, size_type n1,
              const basic_string& str,
              size_type pos2, size_type n);
    

    -5- Requires: pos1 <= size() and pos2 <= str.size().

    -6- Throws: out_of_range if pos1 > size() or pos2 > str.size().

    […]

    basic_string&
      replace(size_type pos1, size_type n1, const charT* s, size_type n2);
    

    -9- Requires: pos1 <= size() and s points to an array of at least n2 elements of charT.

    -10- Throws: out_of_range if pos1 > size() or length_error if the length of the resulting string would exceed max_size() (see below).

    […]

    basic_string&
      replace(size_type pos, size_type n, const charT* s);
    

    -13- Requires: pos <= size() and s points to an array of at least traits::length(s) + 1 elements of charT.

    -14- Effects: Equivalent to return replace(pos, n, s, traits::length(s));.

    -15- Returns: *this.

  10. Modify 21.4.6.7 [string::copy] as indicated:

    size_type copy(charT* s, size_type n, size_type pos = 0) const;
    

    -1- Requires: pos <= size()

    -2- Throws: out_of_range if pos > size().

    […]

  11. Modify 21.4.7.8 [string::substr] as indicated:

    basic_string substr(size_type pos = 0, size_type n = npos) const;
    

    -1- Requires: pos <= size()

    -2- Throws: out_of_range if pos > size().

    […]

  12. Modify 30.3.1.5 [thread.thread.member] as indicated:

    void join();
    

    -3- Requires: joinable() is true.

    […]

    -7- Throws: system_error when an exception is required (30.2.2).

    -8- Error conditions:

    • […]

    • invalid_argument — if the thread is not joinable.

    void detach();
    

    -9- Requires: joinable() is true.

    […]

    -12- Throws: system_error when an exception is required (30.2.2).

    -13- Error conditions:

    • […]

    • invalid_argument — if the thread is not joinable.


2251. C++ library should define ssize_t

Section: 18.2 [support.types] Status: New Submitter: Matt Austern Opened: 2013-04-19 Last modified: 2013-10-15

View all other issues in [support.types].

View all issues with New status.

Discussion:

The C++ standard library defines size_t, a typedef for an implementation defined unsigned integer type that can represent the sizes of objects. The POSIX standard augments this with ssize_t, a typedef for a signed integer type that corresponds to size_t.

The ssize_t typedef is useful — useful enough that the C++ standard even refers to it. (In a non-normative footnote in 27.5.2 [stream.types].) Also, lots of OS vendors add it to their headers anyway, even though it isn't part of the C or C++ standards, because those vendors are trying to define headers that conform to multiple standards at once. We should make users' and implementers' lives easier by adding ssize_t to 18.2 [support.types].

[2013-09-29, Suggested wording from Jayson Oldfather]

I decided to use the phrase to describe ssize_t below because of the text describing it in the POSIX standard. In it, it describes ssize_t with the value range of [-1,{SSIZE_MAX}]. SSIZE_MAX is specified in the POSIX standard as a minimum value of _POSIX_SSIZE_MAX. This macro is referenced in the wording below.

Proposed resolution:

  1. Ammend 18.2 [support.types], Table 30 as indicated:

    Table 30 — Header <cstddef> synopsis
    Type Name(s)
    Macros: NULL offset_t
    Types: ptrdiff_t ssize_t size_t max_align_t nullptr_t

    Add the following paragraph to describe ssize_t

    -?- The type ssize_t is an implementation-defined signed integer type that shall contain the minimum range [-1, {SSIZE_MAX}] where SSIZE_MAX is specified at a minimum of _POSIX_SSIZE_MAX.

    Ammend p7 as follows:

    -7- [Note: It is recommended that implementations choose types for ptrdiff_t, ssize_t, and size_t whose integer conversion ranks …


2252. Strong guarantee on vector::push_back() still broken with C++11?

Section: 23.3.6.5 [vector.modifiers] Status: Ready Submitter: Nicolai Josuttis Opened: 2013-04-21 Last modified: 2013-10-15

View other active issues in [vector.modifiers].

View all other issues in [vector.modifiers].

View all issues with Ready status.

Discussion:

According to my understanding, the strong guarantee of push_back() led to the introduction of noexcept and to the typical implementation that vectors usually copy their elements on reallocation unless the move operations of their element type guarantees not to throw.

However, if I read the standard correctly, we still don't give the strong guarantee any more: Yes, 23.2.1 [container.requirements.general]/10 specifies:

Unless otherwise specified (see 23.2.4.1, 23.2.5.1, 23.3.3.4, and 23.3.6.5) all container types defined in this Clause meet the following additional requirements:

However, 23.3.6.5 [vector.modifiers] specifies for vector modifiers, including push_back():

If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of T or by any InputIterator operation there are no effects. If an exception is thrown by the move constructor of a non-CopyInsertable T, the effects are unspecified.

I would interpret this as an "otherwise specified" behavior for push_back(), saying that the strong guarantee is only given if constructors and assignments do not throw.

That means, the strong guarantee of C++03 is broken with C++11.

In addition to all that 23.2.1 [container.requirements.general] p10 b2 doesn't mention the corresponding functions emplace_back() and emplace_front(). These are similar single-element additions and should provide the same strong guarantee.

Daniel adds:

It seems the error came in when N2350 and N2345 became accepted and where integrated into the working draft N2369. The merge resulted in a form that changed the previous meaning and as far as I understand it, this effect was not intended.

[2013-09-16, Nico provides concrete wording]

[2013-09-26, Nico improves wording]

The new proposed resolution is driven as follows:

Proposed resolution:

This wording is relative to N3691.

  1. Edit 23.2.1 [container.requirements.general] p10 b2 as indicated:

  2. Edit 23.3.3.4 [deque.modifiers] as indicated:

    iterator insert(const_iterator position, const T& x);
    iterator insert(const_iterator position, T&& x);
    iterator insert(const_iterator position, size_type n, const T& x);
    template <class InputIterator>
      iterator insert(const_iterator position,
                      InputIterator first, InputIterator last);
    iterator insert(const_iterator position, initializer_list<T>);
    template <class... Args> void emplace_front(Args&&... args);
    template <class... Args> void emplace_back(Args&&... args);
    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
    void push_front(const T& x);
    void push_front(T&& x);
    void push_back(const T& x);
    void push_back(T&& x);
    

    -1- Effects: An insertion in the middle of the deque invalidates all the iterators and references to elements of the deque. An insertion at either end of the deque invalidates all the iterators to the deque, but has no effect on the validity of references to elements of the deque.

    -2- Remarks: If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of T there are no effects. If an exception is thrown while inserting a single element at either end, there are no effects. IfOtherwise, if an exception is thrown by the move constructor of a non-CopyInsertable T, the effects are unspecified.

    -3- Complexity: The complexity is linear in the number of elements inserted plus the lesser of the distances to the beginning and end of the deque. Inserting a single element either at the beginning or end of a deque always takes constant time and causes a single call to a constructor of T.

  3. Edit 23.3.6.5 [vector.modifiers] as indicated:

    iterator insert(const_iterator position, const T& x);
    iterator insert(const_iterator position, T&& x);
    iterator insert(const_iterator position, size_type n, const T& x);
    template <class InputIterator>
      iterator insert(const_iterator position, InputIterator first, InputIterator last);
    iterator insert(const_iterator position, initializer_list<T>);
    template <class... Args> void emplace_back(Args&&... args);
    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
    void push_back(const T& x);
    void push_back(T&& x);
    

    -1- Remarks: Causes reallocation if the new size is greater than the old capacity. If no reallocation happens, all the iterators and references before the insertion point remain valid. If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of T or by any InputIterator operation there are no effects. If an exception is thrown while inserting a single element at the end and T is CopyInsertable or is_nothrow_move_constructible<T>::value is true, there are no effects. IfOtherwise, if an exception is thrown by the move constructor of a non-CopyInsertable T, the effects are unspecified.

    -2- Complexity: The complexity is linear in the number of elements inserted plus the distance to the end of the vector.


2253. dynarray should state which container requirements aren't met

Section: X [dynarray.overview] Status: Deferred Submitter: Jonathan Wakely Opened: 2013-04-23 Last modified: 2013-10-15

View all issues with Deferred status.

Discussion:

X [dynarray.overview] p2 says:

"Unless otherwise specified, all dynarray operations have the same requirements and semantics as specified in 23.2 [container.requirements]."

Some differences from 23.2 [container.requirements] are not explicitly specified, including at least the lack of a default constructor, copy assignment and swap member.

The wording could be similar to 23.3.2.1 [array.overview] which says "An array satisfies all of the requirements of a container and of a reversible container (23.2 [container.requirements]), except that a default constructed array object is not empty and that swap does not have constant complexity."

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

  1. Add to X [dynarray.overview] p2:

    -2- A dynarray satisfies all of the requirements of a container and of a reversible container (23.2 [container.requirements]), except for default construction, assignment and swap. Unless otherwise specified, all dynarray operations have the same requirements and semantics as specified in 23.2 [container.requirements].


2254. Is dynarray an allocator-aware container?

Section: 23.2.1 [container.requirements.general] Status: Deferred Submitter: Jonathan Wakely Opened: 2013-04-23 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with Deferred status.

Discussion:

23.2.1 [container.requirements.general] p3 says:

"All of the containers defined in this Clause and in (21.4) except array meet the additional requirements of an allocator-aware container, as described in Table 99."

Is this true of dynarray? I believe the answer must be no because dynarray has no allocator_type, and morally should be no, so that operations are defined in terms of std::allocator<T>, which p13 says doesn't actually need to be used (which allows the elements to be default-initialized as is intended, rather than "default-inserted into the container" using an allocator.)

The requirement that "each element is constructed with uses-allocator construction" provides roughly equivalent behaviour to the "CopyInsertable into X" requirements for allocator-aware containers, allowing an allocator to control construction of the dynarray elements.

[2013-09 Chicago]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

  1. Change to 23.2.1 [container.requirements.general] p13:

    -13- All of the containers defined in this Clause and in (21.4) except array and dynarray meet the additional requirements of an allocator-aware container, as described in Table 99.


2255. dynarray constructor ambiguity

Section: X [dynarray.cons] Status: Deferred Submitter: Jonathan Wakely Opened: 2013-04-23 Last modified: 2013-10-15

View all issues with Deferred status.

Discussion:

These constructors can interact badly::

template<class Alloc>
  dynarray(size_type c, const Alloc& alloc);
dynarray(size_type c, const T& v);

Unless the second argument is a value of exactly the type T you will get the first constructor, i.e. all of these will fail to compile:

dynarray<long> dlong(1, 1);   // 1 is not long
dynarray<float> dflt(1, 1.0);  // 1.0 is not float
dynarray<int*> dptr(1, nullptr);  // nullptr is not int*
dynarray<void*> doh(1, 0);  // 0 is not void*

The nullptr case is particularly annoying, a user trying to do the right thing by saying nullptr instead of NULL still gets the wrong result.

The constructor taking an allocator requires that "Alloc shall meet the requirements for an Allocator" but doesn't actually say "shall not participate in overload resolution unless ..."

I believe we have no precedent for using SFINAE to check "the requirements for an Allocator" because it's a pretty complicated set of requirements. We could say it shall not participate in overload resolution if Alloc is implicitly convertible to value_type.

Alternatively, we could follow the same approach used by other types that can be constructed with an unconstrained allocator type and use std::allocator_arg_t as the first argument instead of adding an allocator after the other arguments.

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

  1. Either use the correct way to unambiguously call a constructor taking any type of allocator, i.e. change the constructors to take dynarray(std::allocator_arg_t, const Alloc&, ...) by modifying both the synopsis X [dynarray.overview] p2 and X [dynarray.cons] before p9 like so:

    template <class Alloc>
      dynarray(allocator_arg_t, const Alloc& a, size_type c, const Alloc& alloc);
    template <class Alloc>
      dynarray(allocator_arg_t, const Alloc& a, size_type c, const T& v, const Alloc& alloc);
    template <class Alloc>
      dynarray(allocator_arg_t, const Alloc& a, const dynarray& d, const Alloc& alloc);
    template <class Alloc>
      dynarray(allocator_arg_t, const Alloc& a, initializer_list<T>, const Alloc& alloc);
    
  2. or constrain the problematic constructor by adding a new paragraph to X [dynarray.cons]:

    template <class Alloc>
      dynarray(size_type c, const Alloc& alloc);
    template <class Alloc>
      dynarray(size_type c, const T& v, const Alloc& alloc);
    template <class Alloc>
      dynarray(const dynarray& d, const Alloc& alloc);
    template <class Alloc>
      dynarray(initializer_list<T>, const Alloc& alloc);
    

    -9- Requires: Alloc shall meet the requirements for an Allocator (17.6.3.5 [allocator.requirements]).

    -10- Effects: Equivalent to the preceding constructors except that each element is constructed with uses-allocator construction (20.7.7.2 [allocator.uses.construction]).

    -?- Remarks: The first constructor shall not participate in overload resolution unless Alloc is not implicitly convertible to T.


2256. On vector iterator invalidation

Section: 23.3.6.5 [vector.modifiers] Status: New Submitter: Howard Hinnant Opened: 2013-04-29 Last modified: 2013-10-15

View other active issues in [vector.modifiers].

View all other issues in [vector.modifiers].

View all issues with New status.

Discussion:

23.3.6.5 [vector.modifiers]/p3 says:

iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);

Effects: Invalidates iterators and references at or after the point of the erase.

Consider this example:

#include <vector>
#include <cassert>

int main()
{
  typedef std::vector<int> C;
  C c = {1, 2, 3, 4};
  C::iterator i = c.begin() + 1;
  C::iterator j = c.end() - 1;
  assert(*i == 2);
  assert(*j == 4);
  c.erase(c.begin());
  assert(*i == 3); // Why is this not perfectly fine?!
}

Why has the iterator i been invalidated? It still refers to a perfectly reasonable, fully constructed object. If vector::iterator were to be implemented as a pointer (which is legal), it is not possible for that last line to do anything but run fine.

The iterator j on the other hand now points at end, and any iterators that may now point beyond end(), into uninitialized memory, are clearly invalid.

But why do we say that an iterator that must point to a valid object is invalid? This looks to me like we simply got sloppy in our specification.

Proposed resolution:


2257. Simplify container requirements with the new algorithms

Section: 23.2.1 [container.requirements.general] Status: Ready Submitter: Marshall Clow Opened: 2013-05-29 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with Ready status.

Discussion:

Currently (n3690) Table 96 says, in the row for "a == b", that the Operational semantics are:

== is an equivalence relation.
distance(a.begin(), a.end()) == distance(b.begin(), b.end()) && equal(a.begin(), a.end(),b.begin())

Given the extension of equal for C++14, this can be simplified to:

== is an equivalence relation.
equal(a.begin(), a.end(), b.begin(), b.end())

[ Alisdair notes that a similar edit would apply to the unordered containers requirements. ]

Previous resolution from Marshall Clow:

Ammend the Operational Semantics for 23.2.1 [container.requirements.general], Table 96, row "a == b"

== is an equivalence relation.
distance(a.begin(), a.end()) == distance(b.begin(), b.end()) && equal(a.begin(), a.end(), b.begin(), b.end())

Ammend 23.2.5 [unord.req] p12:

Two unordered containers a and b compare equal if a.size() == b.size() and, for every equivalent-key group [Ea1,Ea2) obtained from a.equal_range(Ea1), there exists an equivalent-key group [Eb1,Eb2) obtained from b.equal_range(Ea1), such that distance(Ea1, Ea2) == distance(Eb1, Eb2) and is_permutation(Ea1, Ea2, Eb1, Eb2) returns true. For ...

[2013-09 Chicago]

Marshall improves wording

[2013-09 Chicago (evening issues)]

Moved to ready, after confirming latest wording reflects the discussion earlier in the day.

Proposed resolution:

  1. Ammend 23.2.1 [container.requirements.general], Table 96 as indicated:

    Table 96 — Container requirements (continued)
    Expression Return type Operational
    semantics
    Assertion/note
    pre-/post-condition
    Complexity
    a == b convertible to bool == is an equivalence relation.
    distance(a.begin(),
    a.end()) ==
    distance(b.begin(),
    b.end()) &&

    equal(a.begin(),
    a.end(),
    b.begin(), b.end())
    Requires: T is
    EqualityComparable
    Constant if a.size() != b.size(), linear otherwise
  2. Ammend 23.2.5 [unord.req] p12:

    Two unordered containers a and b compare equal if a.size() == b.size() and, for every equivalent-key group [Ea1,Ea2) obtained from a.equal_range(Ea1), there exists an equivalent-key group [Eb1,Eb2) obtained from b.equal_range(Ea1), such that distance(Ea1, Ea2) == distance(Eb1, Eb2) and is_permutation(Ea1, Ea2, Eb1, Eb2) returns true. For […]
  3. Amend 23.3.4.1 [forwardlist.overview] p2:

    -2- A forward_list satisfies all of the requirements of a container (Table 96), except that the size() member function is not provided and operator== has linear complexity. […]


2258. a.erase(q1, q2) unable to directly return q2

Section: 23.2.4 [associative.reqmts] Status: New Submitter: Geoff Alexander Opened: 2013-05-11 Last modified: 2013-10-15

View other active issues in [associative.reqmts].

View all other issues in [associative.reqmts].

View all issues with New status.

Discussion:

Section 23.2.4 [associative.reqmts], Table 102, page 743 of the C++ 2011 Standard states that a.erase(q1, q2) returns q2. The problem is that a.erase(q1, q2) cannot directly return q2 as the return type, iterator, differs from that of q2, const_iterator.

[2013-09 Chicago (evening issues group)]

The wording looks good, but is worded slightly differently to how we say the same for sequence containers, and for unordered associative containers. We should apply consistent wording in all three cases.

Alisdair to provide the wording.

Proposed resolution:

  1. In the specification of a.erase(q1, q2) in sub-clause 23.2.4 [associative.reqmts], Table 102 change as indicated:

    Table 102 — Associative container requirements (in addition to container) (continued)
    Expression Return type Assertion/note pre-/post-condition Complexity
    a.erase(q1, q2) iterator erases all the elements in the range [q1,q2). Returns q2an iterator pointing to the same element as q2 or end() if q2 doesn't point to an element. log(a.size()) + N where N has the value distance(q1, q2).

2259. Issues in 17.6.5.5 rules for member functions

Section: 17.6.5.5 [member.functions] Status: New Submitter: Richard Smith Opened: 2013-05-12 Last modified: 2014-01-20

View all other issues in [member.functions].

View all issues with New status.

Discussion:

17.6.5.5 [member.functions] p2 says:

"An implementation may declare additional non-virtual member function signatures within a class:

  1. This wording is not using the correct terminology. "by adding arguments with default values" presumably means "by adding parameters with default arguments", and likewise throughout.

  2. This paragraph only allows an implementation to declare "additional" signatures, but the first bullet is talking about replacing a standard signature with one with additional parameters.

  3. None of these bullets allows a member function with no ref-qualifier to be replaced by signatures with ref-qualifiers (a situation which was just discussed on std-proposals), and likewise for cv-qualifiers. Presumably that is not intentional, and such changes should be permissible.

I think the first two items are probably editorial, since the intent is clear.

[2013-12-11 Richard provides concrete wording]

Proposed resolution:

This wording is relative to N3797.

  1. Merge 17.6.5.5 [member.functions]p2+3 as indicated:

    -2- An implementation may declare additional non-virtual member function signatures within a class:

    • by adding arguments with default values to a member function signature;188 [Note: An implementation may not add arguments with default values to virtual, global, or non-member functions. — end note]

    • by replacing a member function signature with default values by two or more member function signatures with equivalent behavior; and

    • by adding a member function signature for a member function name.

    -3- A call to a member function signature described in the C++ standard library behaves as if the implementation declares no additional member function signatures.[Footnote: A valid C++ program always calls the expected library member function, or one with equivalent behavior. An implementation may also define additional member functions that would otherwise not be called by a valid C++ program.] For a non-virtual member function described in the C++ standard library, an implementation may declare a different set of member function signatures, provided that any call to the member function that would select an overload from the set of declarations described in this standard behaves as if that overload were selected. [Note: For instance, an implementation may add parameters with default values, or replace a member function with default arguments with two or more member functions with equivalent behavior, or add additional signatures for a member function name. — end note]


2260. Missing requirement for Allocator::pointer

Section: 17.6.3.5 [allocator.requirements] Status: Open Submitter: Jonathan Wakely Opened: 2013-05-14 Last modified: 2014-01-20

View other active issues in [allocator.requirements].

View all other issues in [allocator.requirements].

View all issues with Open status.

Discussion:

For an allocator A<T> which defines A<T>::pointer to a class type, i.e. not T*, I see no requirement that A<T>::pointer is convertible to A<U>::pointer, even if T* is convertible to U*. Such conversions are needed in containers to convert from e.g. ListNodeBase* to ListNode<T>*.

The obvious way to do such conversions appears to be pointer_traits::pointer_to(), but that's ill-formed if the static member function A<T>::pointer::pointer_to() doesn't exist and the allocator requirements don't mention that function, so you need to cast A<T>::pointer to A<T>::void_pointer then cast that to A<U>::pointer.

Is converting via void_pointer really intended, or are we missing a requirement that pointer_traits<A<T>::pointer>::pointer_to() be well-formed?

Proposed resolution:

Add to the Allocator requirements table the following requirement:

The expression pointer_traits<XX::pointer>::pointer_to(r) is well-defined.

[2013-09 Chicago]

Pablo to come back with Proposed Wording

Proposed resolution:

  1. Edit Table 28 as indicated:

    Table 28 — Allocator requirements (continued)
    Expression Return type Assertion/note pre-/post-condition Default
    static_cast<X::const_pointer>(z) X::const_pointer static_cast<X::const_pointer>(z) == q  
    pointer_traits<X::pointer>::pointer_to(r) X::pointer    

2261. Are containers required to use their 'pointer' type internally?

Section: 23.2 [container.requirements] Status: New Submitter: Jonathan Wakely Opened: 2013-05-14 Last modified: 2013-10-15

View all other issues in [container.requirements].

View all issues with New status.

Discussion:

Is a container C only supposed to refer to allocated memory (blocks of contiguous storage, nodes, etc.) through objects of type C::pointer rather than C::value_type*?

I don't see anything explicitly requiring this, so a container could immediately convert the result of get_allocator().allocate(1) to a built-in pointer of type value_type* and only deal with the built-in pointer until it needs to deallocate it again, but that removes most of the benefit of allowing allocators to use custom pointer types.

Proposed resolution:


2262. Requirement for unique_ptr<T>::get_deleter()(p) to be able to destroy the unique_ptr

Section: 20.8.1.2 [unique.ptr.single] Status: New Submitter: Rob Desbois Opened: 2013-05-15 Last modified: 2013-10-15

View all other issues in [unique.ptr.single].

View all issues with New status.

Discussion:

N3337 20.8.1.2.5 [unique.ptr.single.modifiers] contains 2 non-normative notes stating:

[para 4]: "The order of these operations is significant because the call to get_deleter() may destroy *this."

[para 5]: "The postcondition does not hold if the call to get_deleter() destroys *this since this->get() is no longer a valid expression."

It seems this wording was created to resolve 998 due to the possibility that a unique_ptr may be destroyed through deletion of its stored pointer where that directly or indirectly refers to the same unique_ptr. If unique_ptr is required to support circular references then it seems this must be normative text: an implementation is currently allowed to operate on *this after the assignment and deletion specified in para 4, since this is only 'disallowed' by the non-normative note.

I propose the following draft rewording:

[para 4]: Effects: assigns p to the stored pointer, and then if the old value of the stored pointer, old_p, was not equal to nullptr, calls get_deleter()(old_p). No operation shall be performed after the call to get_deleter()(old_p) that requires *this to be valid, because the deletion may destroy *this if it is referred to directly or indirectly by the stored pointer. [Note: The order of these operations is significant because the call to get_deleter() may destroy *this. — end note]

[para 5]: Postconditions: If the call get_deleter()(old_p) destroyed *this, none. Otherwise, get() == p. [Note: The postcondition does not hold if the call to get_deleter() destroys *this since this->get() is no longer a valid expression. — end note]

I expect it will also be necessary to amend the requirements for a deleter, so in addition:

20.8.1.2 [unique.ptr.single] [para 1]: The default type for the template parameter D is default_delete. A client-supplied template argument D shall be a function object type (20.10), lvalue-reference to function, or lvalue-reference to function object type for which, given a value d of type D and a value ptr of type unique_ptr<T, D>::pointer, the expression d(ptr) is valid and has the effect of disposing of the pointer as appropriate for that deleter. Where D is not an lvalue reference type, d(ptr) shall be valid if ptr refers directly or indirectly to the invoking unique_ptr object.

[2013-10-05, Stephan T. Lavavej comments and provides alternative wording]

In Chicago, we determined that the original proposed change to 20.8.1.2 [unique.ptr.single]/1 was insufficient, because d might be a reference to a deleter functor that's destroyed during self-destruction.

We believed that 20.8.1.2.5 [unique.ptr.single.modifiers]/4 was already sufficiently clear. The Standard occasionally prevents implementations of X from doing various things, through the principle of "nothing allows X to fail in that situation". For example, v.push_back(v[0]) is required to work for non-empty vectors because nothing allows that to fail. In this case, the intent to allow self-destruction is already clear.

Additionally, we did not believe that 20.8.1.2.5 [unique.ptr.single.modifiers]/5 had to be changed. The current note is slightly squirrely but it does not lead to confusion for implementers or users.

Previous resolution from Rob Desbois:

  1. Edit 20.8.1.2 [unique.ptr.single] p1 as indicated:

    The default type for the template parameter D is default_delete. A client-supplied template argument D shall be a function object type (20.10), lvalue-reference to function, or lvalue-reference to function object type for which, given a value d of type D and a value ptr of type unique_ptr<T, D>::pointer, the expression d(ptr) is valid and has the effect of disposing of the pointer as appropriate for that deleter. Where D is not an lvalue reference type, d(ptr) shall be valid if ptr refers directly or indirectly to the invoking unique_ptr object.

  2. Edit 20.8.1.2.5 [unique.ptr.single.modifiers] p4+5 as indicated:

    void reset(pointer p = pointer()) noexcept;
    

    -3- Requires: The expression get_deleter()(get()) shall be well formed, shall have well-defined behavior, and shall not throw exceptions.

    -4- Effects: assigns p to the stored pointer, and then if the old value of the stored pointer, old_p, was not equal to nullptr, calls get_deleter()(old_p). No operation shall be performed after the call to get_deleter()(old_p) that requires *this to be valid, because the deletion may destroy *this if it is referred to directly or indirectly by the stored pointer. [Note: The order of these operations is significant because the call to get_deleter() may destroy *this. — end note]

    -5- Postconditions: If the call get_deleter()(old_p) destroyed *this, none. Otherwise, get() == p. [Note: The postcondition does not hold if the call to get_deleter() destroys *this since this->get() is no longer a valid expression. — end note]

Proposed resolution:

This wording is relative to N3691.

  1. Edit 20.8.1.2 [unique.ptr.single] p1 as indicated:

    The default type for the template parameter D is default_delete. A client-supplied template argument D shall be a function object type (20.10), lvalue-reference to function, or lvalue-reference to function object type for which, given a value d of type D and a value ptr of type unique_ptr<T, D>::pointer, the expression d(ptr) is valid and has the effect of disposing of the pointer as appropriate for that deleter. d(ptr) shall be valid even if it triggers the destruction of d or (if D is an lvalue reference to function object type) the function object that d refers to.


2263. Comparing iterators and allocator pointers with different const-character

Section: 17.6.3.5 [allocator.requirements], 23.2 [container.requirements] Status: New Submitter: Howard Hinnant Opened: 2013-06-25 Last modified: 2013-10-15

View other active issues in [allocator.requirements].

View all other issues in [allocator.requirements].

View all issues with New status.

Discussion:

This ancient issue 179 says one ought to be able to compare iterators with const_iterators from any given container. I'm having trouble finding words that guarantee this in C++11. This impacts not only a container's iterators, but also the allocator requirements in allocator.requirements] surrounding pointer, const_pointer, void_pointer and const_void_pointer. E.g. can one compare a pointer with a const_pointer?

Since allocator::pointer and const_pointer are required to be random access iterators, one could expect that the 179 guarantees apply for them as well.

[ Daniel comments: ]

The wording for 179 was part of several working drafts (e.g. also in N3092) over some time and suddenly got lost in N3242, presumably by accident. Whatever we decide for allocator pointers, I expect that we need to restore the 179 wording as part of the overall resolution:

Reinsert after 23.2 [container.requirements] p6:

-6- begin() returns an iterator referring to the first element in the container. end() returns an iterator which is the past-the-end value for the container. If the container is empty, then begin() == end();

-?- In the expressions

i == j
i != j
i < j
i <= j
i >= j
i > j
i - j

where i and j denote objects of a container's iterator type, either or both may be replaced by an object of the container's const_iterator type referring to the same element with no change in semantics.

Proposed resolution:


2264. std::dynarray defines its initializer-list constructor in terms of a non-existent constructor

Section: X [dynarray], 23.2 [container.requirements] Status: Deferred Submitter: Povilas Kanapickas Opened: 2013-05-22 Last modified: 2013-10-15

View all issues with Deferred status.

Discussion:

std::dynarray member listing at X [dynarray.overview] includes this constructor:

dynarray(initializer_list<T>);

Also, X [dynarray.overview] p. 2 says:

Unless otherwise specified, all dynarray operations have the same requirements and semantics as specified in 23.2.

The constructor in question isn't mentioned in X [dynarray.cons] or anywhere else. This means requirements from 23.2 [container.requirements] apply. However, Table 100 in 23.2.3 [sequence.reqmts] says:

X(il)               Equivalent to X(il.begin(), il.end())

std::dynarray does not provide this constructor.

The proposed resolution below adds the missing constructor and a complementary constructor with an allocator parameter. The new constructors, differently from the rest of containers, accept iterators that have forward iterator category. This is needed because the size requirements must be known in order to allocate appropriately-sized storage.

An alternative resolution could be to properly specify the initializer-list constructor.

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

  1. Add the following to the std::dynarray synopsis at X [dynarray.overview]:

    namespace std {
      template <class T>
      class dynarray {
        […]
        // 23.3.4.2 construct/copy/destroy:
        […]
        template <class ForwardIterator>
        dynarray(ForwardIterator first, ForwardIterator last);
        template <class ForwardIterator, class Alloc>
        dynarray(ForwardIterator first, ForwardIterator last, const Alloc& alloc);
        […]
      };
    }
    
  2. Add the following to X [dynarray.cons] after p. 8:

    template <class ForwardIterator>
    dynarray(ForwardIterator first, ForwardIterator last);
    

    -?- Requires: T shall meet the CopyConstructible requirements.

    -?- Effects: Allocates storage for distance(first, last) elements. The distance(first, last) elements of the dynarray are direct-initialized (8.5 [dcl.init]) with the corresponding elements from the range [first,last). May or may not invoke the global operator new.

    -?- Complexity: distance(first, last).

    -?- Throws: std::bad_array_length when the size requested is larger than implementable, std::bad_alloc when there is insufficient memory.

  3. Add the following to the list of constructors at X [dynarray.cons] before p. 9:

  4. template <class Alloc>
    dynarray(size_type c, const Alloc& alloc);
    template <class Alloc>
    dynarray(size_type c, const T& v, const Alloc& alloc);
    template <class Alloc>
    dynarray(const dynarray& d, const Alloc& alloc);
    template <class Alloc>
    dynarray(initializer_list<T>, const Alloc& alloc);
    template <class ForwardIterator, class Alloc>
    dynarray(ForwardIterator first, ForwardIterator last, const Alloc& alloc);
    

2265. 29.3p9 appears to rule out some acceptable executions

Section: 29.3 [atomics.order] Status: New Submitter: Brian Demsky Opened: 2013-06-17 Last modified: 2013-10-15

View all other issues in [atomics.order].

View all issues with New status.

Discussion:

I believe that the following variation on IRIW should admit executions in which c1 = d1 = 5 and c2 = d2 = 0. If this is allowed, then what is sequence of program evaluations for 29.3 [atomics.order] p9 that justifies the store to z? It seems that 29.3 [atomics.order] p9 should not allow this execution because one of the stores to x or y has to appear earlier in the sequence, each of the fetch_adds reads the previous load in the thread (and thus must appear later in the sequence), and 29.3 [atomics.order] p9 states that each load must read from the last prior assignment in the sequence.

atomic_int x;
atomic_int y;
atomic_int z;
int c1, c2, d1, d2;

static void a(void* obj)
{
  atomic_store_explicit(&x, 5, memory_order_relaxed); 
}

static void b(void* obj)
{
  atomic_store_explicit(&y, 5, memory_order_relaxed); 
}

static void c(void* obj)
{
  c1 = atomic_load_explicit(&x, memory_order_relaxed);
  // this could also be an atomic load if the address depends on c1:
  c2 = atomic_fetch_add_explicit(&y, c1, memory_order_relaxed);  
}

static void d(void* obj)
{
  d1 = atomic_load_explicit(&y, memory_order_relaxed);
  d2 = atomic_fetch_add_explicit(&x, d1, memory_order_relaxed); 
}

int user_main(int argc, char** argv)
{
  thrd_t t1, t2, t3, t4;

  atomic_init(&x, 0);
  atomic_init(&y, 0);

  printf("Main thread: creating 4 threads\n");
  thrd_create(&t1, (thrd_start_t)&a, NULL);
  thrd_create(&t2, (thrd_start_t)&b, NULL);
  thrd_create(&t3, (thrd_start_t)&c, NULL);
  thrd_create(&t4, (thrd_start_t)&d, NULL);

  thrd_join(t1);
  thrd_join(t2);
  thrd_join(t3);
  thrd_join(t4);
  printf("c1=%d c2=%d\n",c1,c2);
  printf("d1=%d d2=%d\n",d1,d2);

  // Can this store write 1000 (i.e., c1=d1=5, c2=d2=0)?
  atomic_store(&z, (c1+d1)*100+c2+d2);

  printf("Main thread is finished\n");

  return 0;
}

It seems that the easiest fix is to allow a load in 29.3 [atomics.order] p9 to read from any prior store in the evaluation order.

That said, I would personally advocate the following: It seems to me that C/C++ atomics are in a bit of different situation than Java because:

  1. People are expected to use relaxed C++ atomics in potentially racy situations, so it isn't clear that semantics as complicated as the JMM's causality would be sane.

  2. People who use C/C++ atomics are likely to be experts and use them in a very controlled fashion. I would be really surprised if compilers would find any real wins by optimizing the use of atomics.

Why not do something like:

There is satisfaction DAG of all program evaluations. Each evaluation observes the values of variables as computed by some prior assignment in the DAG.

There is an edge x->y between two evaluations x and y if:

  1. the evaluation y observes a value computed by the evaluation x or

  2. the evaluation y is an atomic store, the evaluation x is an atomic load, and there is a condition branch c that may depend (intrathread dependence) on x and x-sb->c and c-sb->y.

This seems to allow reordering of relaxed atomics that processors do without extra fence instructions, allows most reorderings by the compiler, and gets rid of satisfaction cycles.

Proposed resolution:


2266. vector and deque have incorrect insert requirements

Section: 23.2.3 [sequence.reqmts] Status: New Submitter: Ahmed Charles Opened: 2013-05-17 Last modified: 2013-10-15

View other active issues in [sequence.reqmts].

View all other issues in [sequence.reqmts].

View all issues with New status.

Discussion:

According to Table 100 in n3485 23.2.3 [sequence.reqmts]/4 the notes for the expression a.insert(p,i,j) say:

Requires: T shall be EmplaceConstructible into X from *i. For vector, if the iterator does not meet the forward iterator requirements (24.2.5), T shall also be MoveInsertable into X and MoveAssignable.

Each iterator in the range [i,j) shall be dereferenced exactly once.

pre: i and j are not iterators into a.

Inserts copies of elements in [i, j) before p

There are two problems with that wording: First, the special constraints for vector, that are expressed to be valid for forward iterators only, are necessary for all iterator categories. Second, the same special constraints are needed for deque, too.

[2013-10-05, Stephan T. Lavavej comments and provides alternative wording]

In Chicago, we determined that the original proposed resolution was correct, except that it needed additional requirements. When vector insert(p, i, j) is called with input-only iterators, it can't know how many elements will be inserted, which is obviously problematic for insertion anywhere other than at the end. Therefore, implementations typically append elements (geometrically reallocating), followed by rotate(). Given forward+ iterators, some implementations append and rotate() when they determine that there is sufficient capacity. Additionally, deque insert(p, i, j) is typically implemented with prepending/appending, with a possible call to reverse(), followed by a call to rotate(). Note that rotate()'s requirements are strictly stronger than reverse()'s.

Therefore, when patching Table 100, we need to add rotate()'s requirements. Note that this does not physically affect code (implementations were already calling rotate() here), and even in Standardese terms it is barely noticeable — if an element is MoveInsertable and MoveAssignable then it is almost certainly MoveConstructible and swappable. However, this patch is necessary to be strictly correct.

Previous resolution from Ahmed Charles:

  1. Change Table 100 as indicated:

    Table 100 — Sequence container requirements (in addition to container) (continued)
    Expression Return type Assertion/note pre-/post-condition
    a.insert(p,i,j) iterator Requires: T shall be EmplaceConstructible into X from *i. For vector and deque, if the iterator does not meet the forward iterator requirements (24.2.5), T shall also be MoveInsertable into X and MoveAssignable.
    Each iterator in the range [i,j) shall be dereferenced exactly once.
    pre: i and j are not iterators into a.
    Inserts copies of elements in [i, j) before p

Proposed resolution:

  1. Change Table 100 as indicated:

    Table 100 — Sequence container requirements (in addition to container) (continued)
    Expression Return type Assertion/note pre-/post-condition
    a.insert(p,i,j) iterator Requires: T shall be EmplaceConstructible into X
    from *i. For vector and deque, if the iterator
    does not meet the forward iterator requirements (24.2.5), T shall also be
    MoveInsertable into X, MoveConstructible,
    and MoveAssignable, and swappable (17.6.3.2 [swappable.requirements]).
    Each iterator in the range [i,j) shall be dereferenced exactly once.
    pre: i and j are not iterators into a.
    Inserts copies of elements in [i, j) before p

2267. partial_sort_copy underspecified for ranges of two different types

Section: 25.4.1.4 [partial.sort.copy] Status: New Submitter: Matt Austern Opened: 2013-06-26 Last modified: 2013-10-15

View all issues with New status.

Discussion:

The signature of this function is:

template<class InputIterator, class RandomAccessIterator>
RandomAccessIterator
partial_sort_copy(InputIterator first, InputIterator last,
                  RandomAccessIterator result_first,
                  RandomAccessIterator result_last);

(and the usual overload for an explicitly provided comparison function). The standard says nothing about requirements in the case where the input type (iterator_traits<InputIterator>::value_type) and the output type (iterator_traits<RandomAccessIterator>::value_type) are different.

Presumably the input type must be convertible to the output type. What's less clear is what the requirements are on the comparison operator. Does the algorithm only perform comparisons on two values of the output type, or does it also perform comparisons on values of the input type, or might it even perform heterogeneous comparisons?

Proposed resolution:


2268. Setting a default argument in the declaration of a member function assign of std::basic_string

Section: 21.4 [basic.string] Status: Ready Submitter: Vladimir Grigoriev Opened: 2013-06-26 Last modified: 2014-01-20

View other active issues in [basic.string].

View all other issues in [basic.string].

View all issues with Ready status.

Discussion:

Constructors and member functions assign of class std::basic_string have one to one relation (except the explicit constructor that creates an empty string). The following list shows this relation:

explicit basic_string(const Allocator& a = Allocator());

basic_string(const basic_string& str);
basic_string& assign(const basic_string& str);

basic_string(basic_string&& str) noexcept;
basic_string& assign(basic_string&& str) noexcept;

basic_string(const basic_string& str, size_type pos, size_type n = npos,
  const Allocator& a = Allocator());
basic_string& assign(const basic_string& str, size_type pos,
  size_type n);

basic_string(const charT* s,
  size_type n, const Allocator& a = Allocator());
basic_string& assign(const charT* s, size_type n);

basic_string(const charT* s, const Allocator& a = Allocator());
basic_string& assign(const charT* s);

basic_string(size_type n, charT c, const Allocator& a = Allocator());
basic_string& assign(size_type n, charT c);

template<class InputIterator>
basic_string(InputIterator begin, InputIterator end,
  const Allocator& a = Allocator());
template<class InputIterator>
basic_string& assign(InputIterator first, InputIterator last);

basic_string(initializer_list<charT>, const Allocator& = Allocator());
basic_string& assign(initializer_list<charT>);

So in fact any creating of an object of type std::basic_string using any of the above constructors except the explicit constructor can be substituted for creating a (possibly non-empty) string and then applying to it the corresponding method assign.

For example these two code snippets give the same result:

std::string s("Hello World");

and

std::string s;
s.assign("Hello World");

However there is one exception that has no a logical support. It is the pair of the following constructor and member function assign

basic_string(const basic_string& str, size_type pos, size_type n = npos,
             const Allocator& a = Allocator());

basic_string& assign(const basic_string& str, size_type pos, size_type n);

The third parameter of the constructor has a default argument while in the assign function it is absent. So it is impossible one to one to substitute the following code snippet

std::string s("Hello World");
std::string t(s, 6);

by

std::string s("Hello World");
std::string t;
t.assign(s, 6); // error: no such function

To get an equivalent result using the assign function the programmer has to complicate the code that is error-prone

std::string s("Hello World");
std::string t;
t.assign(s, 6, s.size() - 6); 

To fix that, the declaration of the member function assign should be changed in such a way that its declaration would be fully compatible with the declaration of the corresponding constructor, that is to specify the same default argument for the third parameter of the assign.

The assign function is not the only function that requires to be revised.

Now let include in the list of pairs constructor-assign with the modified method assign one more member function append. We will get:

explicit basic_string(const Allocator& a = Allocator());

basic_string(const basic_string& str);
basic_string& assign(const basic_string& str);
basic_string& append(const basic_string& str);

basic_string(basic_string&& str) noexcept;
basic_string& assign(basic_string&& str) noexcept;

basic_string(const basic_string& str, size_type pos, size_type n = npos,
  const Allocator& a = Allocator());
basic_string& assign(const basic_string& str, size_type pos,
  size_type n);
basic_string& append(const basic_string& str, size_type pos,
  size_type n);

basic_string(const charT* s,
  size_type n, const Allocator& a = Allocator());
basic_string& assign(const charT* s, size_type n);
basic_string& append(const charT* s, size_type n);

basic_string(const charT* s, const Allocator& a = Allocator());
basic_string& assign(const charT* s);
basic_string& append(const charT* s);

basic_string(size_type n, charT c, const Allocator& a = Allocator());
basic_string& assign(size_type n, charT c);
basic_string& append(size_type n, charT c);

template<class InputIterator>
basic_string(InputIterator begin, InputIterator end,
  const Allocator& a = Allocator());
template<class InputIterator>
basic_string& assign(InputIterator first, InputIterator last);
template<class InputIterator>
basic_string& append(InputIterator first, InputIterator last);

basic_string(initializer_list<charT>, const Allocator& = Allocator());
basic_string& assign(initializer_list<charT>);
basic_string& append(initializer_list<charT>);

As it seen from this record:

basic_string(const basic_string& str, size_type pos, size_type n = npos,
  const Allocator& a = Allocator());
basic_string& assign(const basic_string& str, size_type pos,
  size_type n);
basic_string& append(const basic_string& str, size_type pos,
  size_type n);

it is obvious that the function append also should have the default argument that is that it should be declared as:

basic_string& append(const basic_string& str, size_type pos,
  size_type n = npos);

In fact there is no a great difference in using assign or append especially when the string is empty:

std::string s("Hello World");
std::string t;
t.assign(s, 6);
 
std::string s("Hello World");
std::string t;
t.append(s, 6);

In both cases the result will be the same. So the assign and append will be interchangeable from the point of view of used arguments.

There are another three member functions in class std::basic_string that could be brought in conformity with considered above functions. They are member functions insert, replace, and compare.

So it is suggested to substitute the following declarations of insert, replace, and compare:

basic_string& insert(size_type pos1, const basic_string& str,
  size_type pos2, size_type n);

basic_string& replace(size_type pos1, size_type n1,
  const basic_string& str, size_type pos2, size_type n2);

int compare(size_type pos1, size_type n1,
  const basic_string& str, size_type pos2, size_type n2) const;

by the declarations:

basic_string& insert(size_type pos1, const basic_string& str,
  size_type pos2, size_type n = npos);

basic_string& replace(size_type pos1, size_type n1,
  const basic_string& str, size_type pos2, size_type n2 = npos);

int compare(size_type pos1, size_type n1,
  const basic_string& str, size_type pos2, size_type n2 = npos) const;

[2013-09 Chicago]

Howard: Are we positive this won't conflict with any other overloads?

They all appear to be unambiguous.

Alisdair: Ok, move to Ready.

Proposed resolution:

  1. Change class template basic_string synopsis, 21.4 [basic.string] p5, as indicated:

    namespace std {
      template<class charT, class traits = char_traits<charT>,
        class Allocator = allocator<charT> >
      class basic_string {
      public:
        […]
        basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
        […]
        basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
        […]
        basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);
        […]
        basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos);
        […]
        int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const;
        […]
      };
    }
    
  2. Change 21.4.6.2 [string::append] before p3 as indicated:

    basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
    
  3. Change 21.4.6.3 [string::assign] before p4 as indicated:

    basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
    
  4. Change 21.4.6.4 [string::insert] before p5 as indicated:

    basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);
    
  5. Change 21.4.6.6 [string::replace] before p5 as indicated:

    basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos);
    
  6. Change 21.4.7.9 [string::compare] before p4 as indicated:

    int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const;
    

2269. Container iterators and argument-dependent lookup

Section: 23.2.1 [container.requirements.general] Status: New Submitter: Matt Austern Opened: 2013-06-26 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with New status.

Discussion:

Consider the following code snippet:

#include <vector>
#include <algorithm>

int main() {
  std::vector<int> v1(100, 3);
  std::vector<int> v2(100);
  copy(v1.begin(), v1.end(), v2.begin());
}

It compiles without error on my desktop. Is it required to? I can't find evidence from the standard that it is. In my test std::copy was found by argument-dependent lookup because the implementation I used made std::vector<int>::iterator a user-defined type defined in namespace std. But the standard only requires std::vector<int>::iterator to be an implementation specified random access iterator type. I can't find anything requiring it to be a user-defined type at all (and in fact there are reasonable implementation where it isn't), let alone a user defined type defined in a specific namespace.

Since the defining namespace of container iterators is visible to users, should the standard say anything about what that namespace is?

Proposed resolution:


2271. regex_traits::lookup_classname specification unclear

Section: 28.7 [re.traits] Status: Ready Submitter: Jonathan Wakely Opened: 2013-07-02 Last modified: 2014-01-20

View other active issues in [re.traits].

View all other issues in [re.traits].

View all issues with Ready status.

Discussion:

28.7 [re.traits] p9 says that regex_traits::lookup_classname should return a value that compares equal to 0, but there is no requirement that a bitmask type is equality comparable with 0, e.g. 17.5.2.1.3 [bitmask.types] says bitmask types can be implemented using std::bitset.

Either there should be an additional requirement on the type or the function definition should be fixed.

[2013-09 Chicago]

Stefanus: Resolution looks good, doesn't seem to need fixing anywhere else from a quick look through the draft.

Any objection to Ready?

No objection.

Action: Move to Ready.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 28.7 [re.traits] p9:

    template <class ForwardIterator>
      char_class_type lookup_classname(
        ForwardIterator first, ForwardIterator last, bool icase = false) const;
    

    -9- Returns: an unspecified value that represents the character classification named by the character sequence designated by the iterator range [first,last). If the parameter icase is true then the returned mask identifies the character classification without regard to the case of the characters being matched, otherwise it does honor the case of the characters being matched. The value returned shall be independent of the case of the characters in the character sequence. If the name is not recognized then returns a value that compares equal to 0char_class_type().


2272. quoted should use char_traits::eq for character comparison

Section: 27.7.6 [quoted.manip] Status: Ready Submitter: Marshall Clow Opened: 2013-07-12 Last modified: 2013-10-15

View other active issues in [quoted.manip].

View all other issues in [quoted.manip].

View all issues with Ready status.

Discussion:

In 27.7.6 [quoted.manip] p2 b2:

— Each character in s. If the character to be output is equal to escape or delim, as determined by operator==, first output escape.

In 27.7.6 [quoted.manip] p3 b1 sb1:

— If the first character extracted is equal to delim, as determined by operator==, […]

these should both use traits::eq.

Also, I believe that 27.7.6 [quoted.manip] p3 implies that:

std::ostream _stream;
std::string _string;
_stream << _string;
_stream << quoted(_string);

should both compile, or both fail to compile, based on whether or not their char_traits match. But I believe that the standard should say that explicitly.

[ 2013-09 Chicago ]

Marshall Clow improved the wording with support from Stefanus.

[ 2013-09 Chicago (late night issues) ]

Moved to Ready, after confirming wording correctly reflects discussion earlier in the day.

Proposed resolution:

This wording is relative to N3691.

  1. Change 27.7.6 [quoted.manip] p2+3 as indicated:

    template <class charT>
      unspecified quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\'));
    template <class charT, class traits, class Allocator>
      unspecified quoted(const basic_string<charT, traits, Allocator>& s,
                         charT delim=charT('"'), charT escape=charT('\\'));
    

    -2- Returns: An object of unspecified type such that if out is an instance of basic_ostream with member type char_type the same as charT and with member type traits_type, which in the second form is the same as traits, then the expression out << quoted(s, delim, escape) behaves as if it inserts the following characters into out using character inserter function templates (27.7.3.6.4), which may throw ios_base::failure (27.5.3.1.1):

    • delim

    • Each character in s. If the character to be output is equal to escape or delim, as determined by operator==traits_type::eq, first output escape.

    • delim

    template <class charT, class traits, class Allocator>
      unspecified quoted(basic_string<charT, traits, Allocator>& s,
                         charT delim=charT('"'), charT escape=charT('\\'));
    

    -3- Returns: An object of unspecified type such that:

    • If in is an instance of basic_istream with member types char_type and traits_type the same as charT and traits, respectively, then the expression in >> quoted(s, delim, escape) behaves as if it extracts the following characters from in using basic_istream::operator>> (27.7.2.2.3) which may throw ios_base::failure (27.5.3.1.1):

      • If the first character extracted is equal to delim, as determined by operator==traits_type::eq, then: […]

    • If out is an instance of basic_ostream with member types char_type and traits_type the same as charT and traits, respectively, then the expression out << quoted(s, delim, escape) behaves as specified for the const basic_string<charT, traits, Allocator>& overload of the quoted function.


2273. regex_match ambiguity

Section: 28.11.2 [re.alg.match] Status: New Submitter: Howard Hinnant Opened: 2013-07-14 Last modified: 2013-10-15

View other active issues in [re.alg.match].

View all other issues in [re.alg.match].

View all issues with New status.

Discussion:

28.11.2 [re.alg.match] p2 in describing regex_match says:

-2- Effects: Determines whether there is a match between the regular expression e, and all of the character sequence [first,last). The parameter flags is used to control how the expression is matched against the character sequence. Returns true if such a match exists, false otherwise.

It has come to my attention that different people are interpreting the first sentence of p2 in different ways:

  1. If a search of the input string using the regular expression e matches the entire input string, regex_match should return true.

  2. Search the input string using the regular expression e. Reject all matches that do not match the entire input string. If a such a match is found, return true.

The difference between these two subtly different interpretations is found using the following ECMAScript example:

std::regex re("Get|GetValue");

Using regex_search, this re can never match the input string "GetValue", because ECMA specifies that alternations are ordered, not greedy. As soon as "Get" is matched in the left alternation, the matching algorithm stops.

Using definition 1, regex_match would return false for an input string of "GetValue".

However definition 2 alters the grammar and appears equivalent to augmenting the regex with a trailing '$', which is an anchor that specifies, reject any matches which do not come at the end of the input sequence. So, using definition 2, regex_match would return true for an input string of "GetValue".

My opinion is that it would be strange to have regex_match return true for a string/regex pair that regex_search could never find. I.e. I favor definition 1.

John Maddock writes:

The intention was always that regex_match would reject any match candidate which didn't match the entire input string. So it would find GetValue in this case because the "Get" alternative had already been rejected as not matching. Note that the comparison with ECMA script is somewhat moot, as ECMAScript defines the regex grammar (the bit we've imported), it does not define anything like regex_match, nor do we import from ECMAScript the behaviour of that function. So IMO the function should behave consistently regardless of the regex dialect chosen. Saying "use awk regexes" doesn't cut it, because that changes the grammar in other ways.

(John favors definition 2).

We need to clarify 28.11.2 [re.alg.match]/p2 in one of these two directions.

Proposed resolution:


2274. Does map::operator[] value-initialize or default-insert a missing element?

Section: 23.4.4.3 [map.access], 23.5.4.3 [unord.map.elem] Status: Open Submitter: Andrzej Krzemieński Opened: 2013-07-16 Last modified: 2014-01-20

View all other issues in [map.access].

View all issues with Open status.

Discussion:

Suppose that I provide a custom allocator for type int, that renders value 1 rather than 0 in default-insertion:

struct Allocator1 : std::allocator<int>
{
  using super = std::allocator<int>;

  template<typename Up, typename... Args>
  void construct(Up* p, Args&&... args)
  { super::construct(p, std::forward<Args>(args)...); }

  template<typename Up>
  void construct(Up* p)
  { ::new((void*)p) Up(1); }
};

Now, if I use this allocator with std::map, and I use operator[] to access a not-yet-existent value, what value of the mapped_type should be created? 0 (value-initialization) or 1 (default-insertion):

map<string, int, less<string>, Allocator1> map;
cout << map["cat"];

N3960 is not very clear. 23.4.4.3 [map.access] in para 1 says:

"If there is no key equivalent to x in the map, inserts value_type(x, T()) into the map."

So, it requires value-initialization.

But para 2 says:

"mapped_type shall be DefaultInsertable into *this."

This implies default-insertion, because if not, why the requirement. Also similar functions like vector::resize already require default-insertion wherever they put DefaultInsertable requirements.

Not to mention that default-insertion is more useful, because it allows custom allocators to "override" the default value of mapped_type.

[2013-09 Chicago]

Alisdair: Matters only for POD or trivial types

Marshall: issue might show up elsewhere other than map<>

Alisdair: initialize elements in any containers — by calling construct on allocator traits

Marshall: existing wording is clear

Alisdair: main concern is difference in wording, discusses default initialization

Nico: different requirement needed

Alisdair: gut is issue is NAD, brings up DefaultInsertable definition — discusses definition

Nico: why do we have the requirement?

Alisdair: other containers have this requirement

Marshall: this applies to many other containers

Nico: deque<> in particular

Alisdair: discusses allocator construct

Alisdair: wording raises concerns that aren't said in existing standard

Nico: sees no benefit to change

Marshall: leery of change

Alisdair: can be made clearer; might need to add note to DefaultInsertable; borderline editorial, comfortable without note, willing to wait until other issues arise. close issue as NAD

Proposed resolution:

This wording is relative to N3691.

  1. Change 23.4.4.3 [map.access] p1+p5 as indicated:

    T& operator[](const key_type& x);
    

    -1- Effects: If there is no key equivalent to x in the map, inserts value_type(x, T()) into the mapinto the map a value with key_type initialized using expression x and mapped_type initialized by default-insertion.

    -2- Requires: key_type shall be CopyInsertable and mapped_type shall be DefaultInsertable into *this.

    […]

    T& operator[](key_type&& x);
    

    -5- Effects: If there is no key equivalent to x in the map, inserts value_type(std::move(x), T()) into the mapinto the map a value with key_type initialized using expression std::move(x) and mapped_type initialized by default-insertion.

    -6- Requires: mapped_type shall be DefaultInsertable into *this.

  2. Change 23.5.4.3 [unord.map.elem] p2 as indicated:

    mapped_type& operator[](const key_type& k);
    mapped_type& operator[](key_type&& k);
    

    -1- Requires: mapped_type shall be DefaultInsertable into *this. For the first operator, key_type shall be CopyInsertable into *this. For the second operator, key_type shall be MoveConstructible.

    -2- Effects: If the unordered_map does not already contain an element whose key is equivalent to k, the first operator inserts the value value_type(k, mapped_type())a value with key_type initialized using expression x and mapped_type initialized by default-insertion and the second operator inserts the value value_type(std::move(k), mapped_type())a value with key_type initialized using expression std::move(x) and mapped_type initialized by default-insertion.


2276. Missing requirement on std::promise::set_exception

Section: 30.6 [futures] Status: New Submitter: Jonathan Wakely Opened: 2013-07-30 Last modified: 2013-10-15

View all other issues in [futures].

View all issues with New status.

Discussion:

The standard does not specify the behaviour of this program:

#include <future>
#include <cassert>

struct NonTrivial
{
  NonTrivial() : init(true) { }
  ~NonTrivial() { assert(init); }
  bool init;
};

int main()
{
  std::promise<NonTrivial> p;
  auto f = p.get_future();
  p.set_exception(std::exception_ptr());
  f.get();
}

The standard doesn't forbid making the state ready with a null exception_ptr, so what should get() return? There's no stored exception to throw, but it can't return a value because none was initialized.

A careful reading of the standard shows 30.6.4 [futures.state] p8 says "A shared state is ready only if it holds a value or an exception ready for retrieval." One can infer from the fact that set_exception() makes the state ready that it must store a value or exception, so cannot store "nothing", but that isn't explicit.

The promise::set_exception() and promise::set_exception_at_thread_exit() members should require p != nullptr or should state the type of exception thrown if p is null.

Proposed resolution:


2277. <dynarray> is missing in 24.7/1

Section: 24.7 [iterator.range] Status: Deferred Submitter: Cassio Neri Opened: 2013-07-31 Last modified: 2013-10-15

View other active issues in [iterator.range].

View all other issues in [iterator.range].

View all issues with Deferred status.

Discussion:

Section 24.7 [iterator.range] p1 specifies header files that, in addition to <iterator>, make available the function templates in 24.7 (begin, end, etc.) but it fails to mention <dynarray>. This seems to be just an oversight.

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

This wording is relative to N3691.

  1. Modify 24.7 [iterator.range] p1 as indicated:

    -1- In addition to being available via inclusion of the <iterator> header, the function templates in 24.7 are available when any of the following headers are included: <array>, <deque>, <dynarray>, <forward_list>, <list>, <map>, <regex>, <set>, <string>, <unordered_map>, <unordered_set>, and <vector>.


2278. User-defined literals for Standard Library types

Section: 20.12.2 [time.syn], 21.3 [string.classes] Status: Ready Submitter: Howard Hinnant Opened: 2013-07-22 Last modified: 2013-10-15

View all issues with Ready status.

Discussion:

This paper adds user-defined literals for string, complex and chrono types. It puts each new literal signature in an inline namespace inside of std. Section 3.1 of the paper gives the rationale for doing this:

As a common schema this paper proposes to put all suffixes for user defined literals in separate inline namespaces that are below the inline namespace std::literals. [Note: This allows a user either to do a using namespace std::literals; to import all literal operators from the standard available through header file inclusion, or to use using namespace std::string_literals; to just obtain the literals operators for a specific type. — end note]

This isn't how inline namespaces work.

7.3.1 [namespace.def]/p8 says in part:

Members of an inline namespace can be used in most respects as though they were members of the enclosing namespace. Specifically, the inline namespace and its enclosing namespace are both added to the set of associated namespaces used in argument-dependent lookup (3.4.2) whenever one of them is, and a using- directive (7.3.4) that names the inline namespace is implicitly inserted into the enclosing namespace as for an unnamed namespace (7.3.1.1). […]

I.e. these literals will appear to the client to already be imported into namespace std. The rationale in the paper appears to indicate that this is not the intended behavior, and that instead the intended behavior is to require the user to say:

using namespace std::literals;

or:

using namespace std::literals::string_literals;

prior to use. To get this behavior non-inlined (normal) namespaces must be used.

Originally proposed resolution:

Strike the use of "inline" from each use associated with literals, string_literals, chrono_literals.

My opinion is that this must be done prior to publishing C++14, otherwise we are stuck with this (apparently unwanted) decision forever.

Marshall Clow:

The rationale that I recall was that:

  1. Users could write "using namespace std::literals;" to get all the literal suffixes, or

  2. Users could write "using namespace std::literals::string_literals;" or "using namespace std::literals::chrono_literals;" to get a subset of the suffixes.

To accomplish that, I believe that:

  1. Namespace "std::literals" should not be inline

  2. Namespaces "std::literals::string_literals" and "std::literals::chrono_literals" should be inline

Further details see also reflector message c++std-lib-34256.

Previous resolution from Marshall Clow:

  1. Modify header <chrono> synopsis, 20.12.2 [time.syn], as indicated:

    namespace std {
    namespace chrono {
    […]
    } // namespace chrono
    inline namespace literals {
    inline namespace chrono_literals {
    […]
    } // namespace chrono_literals
    } // namespace literals
    } // namespace std
    
  2. Modify header <string> synopsis, 21.3 [string.classes] p1, as indicated:

    #include <initializer_list>
    
    namespace std {
    […]
    inline namespace literals {
    inline namespace string_literals {
    […]
    }
    }
    }
    

[2013-09 Chicago]

After a discussion about intent, the conclusion was that if you hoist a type with a "using" directive, then you should also get the associated literal suffixes with the type.

This is accomplished by marking namespace std::literals as inline, but for types in their own namespace inside std, then they will need to do this as well. The only case in the current library is chrono.

Marshall Clow provides alternative wording.

[2013-09 Chicago (late night issues)]

Moved to Ready, after confirming wording reflects the intent of the earlier discussion.

Proposed resolution:

This wording is relative to N3691.

  1. Modify header <chrono> synopsis, 20.12.2 [time.syn], as indicated:

    namespace std {
    […]
    inline namespace literals {
    inline namespace chrono_literals {
    […]
    constexpr chrono::duration<unspecified , nano> operator "" ns(long double);
    
    } // namespace chrono_literals
    } // namespace literals
    
    
    namespace chrono {
        using namespace literals::chrono_literals;
    } // namespace chrono
    
    } // namespace std
    

2280. begin/end for arrays should be constexpr and noexcept

Section: 24.7 [iterator.range] Status: Ready Submitter: Andy Sawyer Opened: 2013-08-22 Last modified: 2014-01-20

View other active issues in [iterator.range].

View all other issues in [iterator.range].

View all issues with Ready status.

Discussion:

The array forms of std::begin and std::end should be constexpr and noexcept.

Previous resolution from Andy Sawyer:

  1. Edit header <iterator> synopsis, 24.3 [iterator.synopsis] as indicated:

    […]
    template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
    template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
    template <class C> constexpr auto cbegin(const C& c) -> decltype(std::begin(c));
    template <class C> constexpr auto cend(const C& c) -> decltype(std::end(c));
    […]
    
  2. Edit 24.7 [iterator.range] before p4+5 as indicated:

    template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
    

    -4- Returns: array.

    template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
    

    -5- Returns: array + N.

    template <class C> constexpr auto cbegin(const C& c) -> decltype(std::begin(c));
    

    -6- Returns: std::begin(c).

    template <class C> constexpr auto cend(const C& c) -> decltype(std::end(c));
    

    -7- Returns: std::end(c).

[2013-09 Chicago]

Add noexcept(noexcept(std::begin/end(c))) to cbegin and cend, move to ready

Proposed resolution:

This wording is relative to N3797.

  1. Edit header <iterator> synopsis, 24.3 [iterator.synopsis] as indicated:

    […]
    template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
    template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
    template <class C> constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c))) -> decltype(std::begin(c));
    template <class C> constexpr auto cend(const C& c) noexcept(noexcept(std::end(c))) -> decltype(std::end(c));
    […]
    
  2. Edit 24.7 [iterator.range] before p4+5 as indicated:

    template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
    

    -4- Returns: array.

    template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
    

    -5- Returns: array + N.

    template <class C> constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c))) -> decltype(std::begin(c));
    

    -6- Returns: std::begin(c).

    template <class C> constexpr auto cend(const C& c) noexcept(noexcept(std::end(c))) -> decltype(std::end(c));
    

    -7- Returns: std::end(c).


2282. Incorrect is_assignable constraint in optional::op=(U&&)

Section: X [optional.object.assign] Status: Deferred Submitter: Howard Hinnant Opened: 2013-08-25 Last modified: 2013-10-15

View other active issues in [optional.object.assign].

View all other issues in [optional.object.assign].

View all issues with Deferred status.

Discussion:

Minor wording nit in X [optional.object.assign]/p15:

template <class U> optional<T>& operator=(U&& v);

-15- Requires: is_constructible<T, U>::value is true and is_assignable<U, T>::value is true.

Should be:

template <class U> optional<T>& operator=(U&& v);

-15- Requires: is_constructible<T, U>::value is true and is_assignable<T&, U>::value is true.

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

This wording is relative to N3691.

  1. Edit X [optional.object.assign] p15 as indicated:

    template <class U> optional<T>& operator=(U&& v);
    

    -15- Requires: is_constructible<T, U>::value is true and is_assignable<U, TT&, U>::value is true.


2283. optional declares and then does not define an operator<()

Section: X [optional.comp_with_t] Status: Deferred Submitter: Howard Hinnant Opened: 2013-08-26 Last modified: 2013-10-15

View all issues with Deferred status.

Discussion:

In [optional.syn] there is:

template <class T> constexpr bool operator<(const T&, const optional<T>&);

But I can find no definition for this signature.

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

This wording is relative to N3691.

  1. Add to X [optional.comp_with_t]:

    template <class T> constexpr bool operator<(const T& v, const optional<T>& x);
    

    -?- Returns: bool(x) ? less<T>{}(v, *x) : false.


2285. make_reverse_iterator

Section: 24.5.1 [reverse.iterators] Status: Ready Submitter: Zhihao Yuan Opened: 2013-08-27 Last modified: 2014-01-20

View other active issues in [reverse.iterators].

View all other issues in [reverse.iterators].

View all issues with Ready status.

Discussion:

We have make_move_iterator, but not make_reverse_iterator, which is also useful when dealing with some types without an rbegin/rend support (like, C strings).

[2013-09 Chicago]

Billy: reviewed it last night STL: has suggested prior, but denied for complexity

Billy: Alisdair wanted to review for reverse(reverse());

STL: likes the issue, was like him

Stefanus: likes definitions, places where things should be

STL: for consistency with make_move_iterator

Stefanus: minor editorial issue - subdivision in these 2 sections is different from [move.iter]. See 24.5.3.3.14 [move.iter.nonmember]

STL: motion to move to Ready

Move to Ready

Proposed resolution:

This wording is relative to N3691.

  1. Change header <iterator> synopsis, 24.3 [iterator.synopsis] as indicated:

    namespace std {
      […]
      template <class Iterator>
        reverse_iterator<Iterator> operator+(
          typename reverse_iterator<Iterator>::difference_type n,
          const reverse_iterator<Iterator>& x);
    
      template <class Iterator>
        reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
    
    }
    
  2. Change class template reverse_iterator synopsis, 24.5.1.1 [reverse.iterator] as indicated:

    namespace std {
      […]
      template <class Iterator>
        reverse_iterator<Iterator> operator+(
          typename reverse_iterator<Iterator>::difference_type n,
          const reverse_iterator<Iterator>& x);
    
      template <class Iterator>
        reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
    
    }
    
  3. After 24.5.1.3.20 [reverse.iter.opsum] add the following new sub-clause to 24.5.1.3 [reverse.iter.ops]:

    
    template <class Iterator>
      reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
    
    

    -?- Returns: reverse_iterator<Iterator>(i).


2286. stringbuf::underflow() underspecified

Section: 27.8.2.4 [stringbuf.virtuals] Status: New Submitter: Sergey Zubkov Opened: 2013-08-29 Last modified: 2013-10-15

View all other issues in [stringbuf.virtuals].

View all issues with New status.

Discussion:

In 27.8.2.4 [stringbuf.virtuals]/1, basic_stringbuf::underflow() is specified to unconditionally return traits::eof() when a read position is not available.

The semantics of basic_stringbuf require, and existing libraries implement it so that this function makes a read position available if possible to do so, e.g. if some characters were inserted into the stream since the last call to overflow(), resulting in pptr() > egptr(). Compare to the conceptually similar D.7.1.3 [depr.strstreambuf.virtuals]/15.

Proposed resolution:

This wording is relative to N3691.

  1. Change 27.8.2.4 [stringbuf.virtuals] as indicated:

    int_type underflow();
    

    -1- Returns: If the input sequence has a read position available or the function makes a read position available (as described below), returns traits::to_int_type(*gptr()). Otherwise, returns traits::eof(). Any character in the underlying buffer which has been initialized is considered to be part of the input sequence.

    -?- The function can make a read position available only if (mode & ios_base::in) != 0 and if the write next pointer pptr() is not null and is greater than the current read end pointer egptr(). To make a read position available, the function alters the read end pointer egptr() to equal pptr().


2287. Incorrect exception safety for optional copy assignment operator

Section: X [optional.object.assign] Status: Deferred Submitter: Howard Hinnant Opened: 2013-08-16 Last modified: 2013-10-15

View other active issues in [optional.object.assign].

View all other issues in [optional.object.assign].

View all issues with Deferred status.

Discussion:

The Exception safety paragraph of X [optional.object.assign] calls out T's copy constructor when it should refer to T's copy assignment operator.

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisitted then.

Proposed resolution:

This wording is relative to N3691.

  1. Change X [optional.object.assign] as indicated:

    optional<T>& operator=(const optional<T>& rhs);
    

    […]

    -8- Exception safety: If any exception is thrown, the values of init and rhs.init remain unchanged. If an exception is thrown during the call to T's copy constructor, no effect. If an exception is thrown during the call to T's copy assignment, the state of its contained value is as defined by the exception safety guarantee of T's copy constructorassignment.


2288. Inconsistent requirements for shared mutexes

Section: 30.4.1.4 [thread.sharedmutex.requirements] Status: New Submitter: Daniel Krügler Opened: 2013-08-30 Last modified: 2013-10-15

View all issues with New status.

Discussion:

Albeit shared mutex types refine timed mutex types, the requirements imposed on the corresponding required member function expressions are inconsistent in several aspects, most probably because failing synchronisation with wording changes for timed mutexes applied by some issues:

  1. Due to acceptance of N3568 a wording phrase came in 30.4.1.4 [thread.sharedmutex.requirements] p26,

    Effects: If the tick period of rel_time is not exactly convertible to the native tick period, the duration shall be rounded up to the nearest native tick period. […]

    while a very similar one had been removed for 30.4.1.3 [thread.timedmutex.requirements] by LWG 2091.

    Having this guaranteed effect for try_lock_shared_for but not for try_lock_for seems inconsistent and astonishing.

    If the actual intended restriction imposed onto the implementation is to forbid early wakeups here, we should ensure that to hold for timed mutex's try_lock_for as well. Note that the rationale provided for LWG 2091 was a potential late wakeup situation, but it seems that there is no implementation restriction that prevents early wakeups.

  2. The shared-lock requirements for any *lock*() functions don't provide the guarantee that "If an exception is thrown then a lock shall not have been acquired for the current execution agent.". For other mutex types this guarantee can be derived from the corresponding TimedLockable requirements, but there are no SharedLockable requirements.

  3. The shared-lock requirements for *lock_for/_until() functions require "Throws: Nothing." instead of "Throws: Timeout-related exceptions (30.2.4)." which had been added by LWG 2093, because user-provided clocks, durations, or time points may throw exceptions.

  4. With the addition of std::shared_mutex, the explicit lists of 30.4.1.2 [thread.mutex.requirements.mutex] p7+15,

    Requires: If m is of type std::mutex or std::timed_mutex, the calling thread does not own the mutex.

    and of 30.4.1.3 [thread.timedmutex.requirements] p4+11,

    Requires: If m is of type std::timed_mutex, the calling thread does not own the mutex.

    are incomplete and should add the non-recursive std::shared_mutex as well.

Proposed resolution:

This wording is relative to N3691.

  1. Change 30.4.1.2 [thread.mutex.requirements.mutex] p7+15 as indicated:

    -6- The expression m.lock() shall be well-formed and have the following semantics:

    -7- Requires: If m is of type std::mutex or, std::timed_mutex, or std::shared_mutex, the calling thread does not own the mutex.

    […]

    -14- The expression m.try_lock() shall be well-formed and have the following semantics:

    -15- Requires: If m is of type std::mutex or, std::timed_mutex, or std::shared_mutex, the calling thread does not own the mutex.

  2. Change 30.4.1.3 [thread.timedmutex.requirements] p4+11 as indicated:

    -3- The expression m.try_lock_for(rel_time) shall be well-formed and have the following semantics:

    -4- Requires: If m is of type std::timed_mutex or std::shared_mutex, the calling thread does not own the mutex.

    […]

    -10- The expression m.try_lock_until(abs_time) shall be well-formed and have the following semantics:

    -11- Requires: If m is of type std::timed_mutex or std::shared_mutex, the calling thread does not own the mutex.

  3. Change 30.4.1.4 [thread.sharedmutex.requirements] as indicated:

    -3- The expression m.lock_shared() shall be well-formed and have the following semantics:

    -4- Requires: The calling thread has no ownership of the mutex.

    -5- Effects: Blocks the calling thread until shared ownership of the mutex can be obtained for the calling thread. If an exception is thrown then a shared lock shall not have been acquired for the current thread.

    […]

    -24- The expression m.try_lock_shared_for(rel_time) shall be well-formed and have the following semantics:

    -25- Requires: The calling thread has no ownership of the mutex.

    -26- Effects: If the tick period of rel_time is not exactly convertible to the native tick period, the duration shall be rounded up to the nearest native tick period. Attempts to obtain shared lock ownership for the calling thread within the relative timeout (30.2.4) specified by rel_time. If the time specified by rel_time is less than or equal to rel_time.zero(), the function attempts to obtain ownership without blocking (as if by calling try_lock_shared()). The function shall return within the timeout specified by rel_time only if it has obtained shared ownership of the mutex object. [Note: As with try_lock(), there is no guarantee that ownership will be obtained if the lock is available, but implementations are expected to make a strong effort to do so. — end note] If an exception is thrown then a shared lock shall not have been acquired for the current thread.

    […]

    -30- Throws: NothingTimeout-related exceptions (30.2.4 [thread.req.timing]).

    -31- The expression m.try_lock_shared_until(abs_time) shall be well-formed and have the following semantics:

    -32- Requires: The calling thread has no ownership of the mutex.

    -33- Effects: The function attempts to obtain shared ownership of the mutex. If abs_time has already passed, the function attempts to obtain shared ownership without blocking (as if by calling try_lock_shared()). The function shall return before the absolute timeout (30.2.4) specified by abs_time only if it has obtained shared ownership of the mutex object. [Note: As with try_lock(), there is no guarantee that ownership will be obtained if the lock is available, but implementations are expected to make a strong effort to do so. — end note] If an exception is thrown then a shared lock shall not have been acquired for the current thread.

    […]

    -37- Throws: NothingTimeout-related exceptions (30.2.4 [thread.req.timing]).


2289. constexpr guarantees of defaulted functions still insufficient

Section: 20.3.2 [pairs.pair], 20.4.2.1 [tuple.cnstr], 20.12.5 [time.duration] Status: New Submitter: Daniel Krügler Opened: 2013-09-09 Last modified: 2013-10-15

View all other issues in [pairs.pair].

View all issues with New status.

Discussion:

During the acceptance of N3471 and some similar constexpr papers, specific wording was added to pair, tuple, and other templates that were intended to impose implementation constraints that ensure that the observable constexpr "character" of a defaulted function template is solely determined by the required expressions of the user-provided types when instantiated, for example:

The defaulted move and copy constructor, respectively, of pair shall be a constexpr function if and only if all required element-wise initializations for copy and move, respectively, would satisfy the requirements for a constexpr function.

This wording doesn't require enough, especially since the core language via CWG 1358 does now support constexpr function template instantiations, even if such function cannot appear in a constant expression (as specified in 5.19 [expr.const]) or as a constant initializer of that object (as specified in 3.6.2 [basic.start.init]). The wording should be improved and should require valid uses in constant expressions and as constant initializers instead.

Proposed resolution:

This wording is relative to N3691.

  1. Change 20.3.2 [pairs.pair] p2 as indicated:

    -2- The defaulted move and copy constructor, respectively, of pair shall be a constexpr function if and only if all required element-wise initializations for copy and move, respectively, would satisfy the requirements for a constexpr functionAn invocation of the move or copy constructor of pair shall be a constant expression (5.19 [expr.const]) if all required element-wise initializations would be constant expressions. An invocation of the move or copy constructor of pair shall be a constant initializer for that pair object (3.6.2 [basic.start.init]) if all required element-wise initializations would be constant initializers for the respective subobjects.

  2. Change 20.4.2.1 [tuple.cnstr] p2 as indicated:

    -2- The defaulted move and copy constructor, respectively, of tuple shall be a constexpr function if and only if all required element-wise initializations for copy and move, respectively, would satisfy the requirements for a constexpr function. The defaulted move and copy constructor of tuple<> shall be constexpr functionsAn invocation of the move or copy constructor of tuple shall be a constant expression (5.19 [expr.const]) if all required element-wise initializations would be constant expressions. An invocation of the move or copy constructor of tuple shall be a constant initializer for that tuple object (3.6.2 [basic.start.init]) if all required element-wise initializations would be constant initializers for the respective subobjects. An invocation of the move or copy constructor of tuple<> shall be a constant expression, or a constant initializer for that tuple<> object, respectively, if the function argument would be constant expression.

  3. Change 20.12.5 [time.duration] p7 as indicated:

    -7- Remarks: The defaulted copy constructor of duration shall be a constexpr function if and only if the required initialization of the member rep_ for copy and move, respectively, would satisfy the requirements for a constexpr function.An invocation of the copy constructor of duration shall be a constant expression (5.19 [expr.const]) if the required initialization of the member rep_ would be a constant expression. An invocation of the copy constructor of duration shall be a constant initializer for that duration object (3.6.2 [basic.start.init]) if the required initialization of the member rep_ would be constant initializers for this subobject.


2290. Top-level "SFINAE"-based constraints should get a separate definition in Clause 17

Section: 20.10 [meta] Status: New Submitter: Daniel Krügler Opened: 2013-09-02 Last modified: 2013-10-15

View all other issues in [meta].

View all issues with New status.

Discussion:

The current library specification uses at several places wording that is intended to refer to core language template deduction failure at the top-level of expressions (aka "SFINAE"), for example:

The expression declval<T>() = declval<U>() is well-formed when treated as an unevaluated operand (Clause 5). Access checking is performed as if in a context unrelated to T and U. Only the validity of the immediate context of the assignment expression is considered. [Note: The compilation of the expression can result in side effects such as the instantiation of class template specializations and function template specializations, the generation of implicitly-defined functions, and so on. Such side effects are not in the “immediate context” and can result in the program being ill-formed. — end note]

Similar wording can be found in the specification of result_of, is_constructible, and is_convertible, being added to resolve an NB comment by LWG 1390 and 1391 through N3142.

This wording is necessary to limit speculative compilations needed to implement these traits, but it is also lengthy and repetitive.

Proposed resolution:


2291. std::hash is vulnerable to collision DoS attack

Section: 17.6.3.4 [hash.requirements] Status: Ready Submitter: Zhihao Yuan Opened: 2013-09-02 Last modified: 2013-10-15

View all other issues in [hash.requirements].

View all issues with Ready status.

Discussion:

For a non-cryptographic hash function, it's possible to pre-calculate massive inputs with the same hashed value to algorithmically slow down the unordered containers, and results in a denial-of-service attack. Many languages with built-in hash table support have fixed this issue. For example, Perl has universal hashing, Python 3 uses salted hashes.

However, for C++, in 17.6.3.4 [hash.requirements] p2, Table 26:

The value returned shall depend only on the argument k. [Note: Thus all evaluations of the expression h(k) with the same value for k yield the same result. — end note]

The wording is not clear here: does that mean all the standard library implementations must use the same hash function for a same type? Or it is not allowed for an implementation to change its hash function?

I suggest to explicitly allow the salted hash functions.

[2013-09 Chicago]

Moved to Ready.

There is some concern that the issue of better hashing, especially standardizing any kind of secure hashing, is a feature that deserves attention in LEWG

The proposed resolution is much simpler than the larger issue though, merely clarifying a permission that many implementers believe they already have, without mandating a change to more straight forward implementations.

Move to Ready, rather than Immediate, as even the permission has been contentious in reflector discussion, although the consensus in Chicago is to accept as written unless we hear a further strong objection.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 17.6.3.4 [hash.requirements] p2, Table 26, as indicated: [Editorial note: We can consider adding some additional guideline here. Unlike N3333, this proposed change makes the hashing per-execution instead of per-process. The standard does not discuss OS processes. And, practically, a per-process hashing makes a program unable to share an unordered container to a child process. — end note ]

    Table 26 — Hash requirements [hash]
    Expression Return type Requirement
    h(k) size_t The value returned shall depend only on the argument k
    for the duration of the program.
    [Note: Thus all evaluations of the expression h(k) with the
    same value for k yield the same result for a given
    execution of the program
    . — end note]

2292. Find a better phrasing for "shall not participate in overload resolution"

Section: 17.5.1.4 [structure.specifications] Status: New Submitter: Jeffrey Yasskin Opened: 2013-09-03 Last modified: 2013-10-15

View all other issues in [structure.specifications].

View all issues with New status.

Discussion:

The C++14 CD has 25 sections including the phrase "X shall not participate in overload resolution ...". Most of these uses are double negatives, which are hard to interpret. "shall not ... unless" tends to be the easiest to read, since the condition is true when the function is available, but we also have a lot of "if X is not Y, then Z shall not participate", which actually means "You can call Z if X is Y." The current wording is also clumsy and long-winded. We should find a better and more concise phrasing.

As an initial proposal, I'd suggest using "X is enabled if and only if Y" in prose and adding an "Enabled If: ..." element to 17.5.1.4 [structure.specifications].

Daniel:

I suggest to name this new specification element for 17.5.1.4 [structure.specifications] as "Template Constraints:" instead, because the mentioned wording form was intentionally provided starting with LWG 1237 to give implementations more freedom to realize the concrete constraints. Instead of the original std::enable_if-based specifications we can use better forms of "SFINAE" constraints today and it eases the path to possible language-based constraints in the future.

Proposed resolution:


2293. Wrong facet used by num_put::do_put

Section: 22.4.2.2.2 [facet.num.put.virtuals] Status: New Submitter: Juan Soulie Opened: 2013-09-04 Last modified: 2013-10-15

View other active issues in [facet.num.put.virtuals].

View all other issues in [facet.num.put.virtuals].

View all issues with New status.

Discussion:

At the end of 22.4.2.2.2 [facet.num.put.virtuals] (in p6), the return value is said to be obtained by calling truename or falsename on the wrong facet: ctype should be replaced by numpunct.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 22.4.2.2.2 [facet.num.put.virtuals] p6 as indicated:

    -6- Returns: If (str.flags() & ios_base::boolalpha) == 0 returns do_put(out, str, fill, (int)val), otherwise obtains a string s as if by

    string_type s =
      val ? use_facet<ctypenumpunct<charT> >(loc).truename()
          : use_facet<ctypenumpunct<charT> >(loc).falsename();
    

    and then inserts each character c of s into out via *out++ = c and returns out.


2294. <cstdlib> should declare abs(double)

Section: 26.8 [c.math] Status: Open Submitter: Pete Becker Opened: 2013-09-04 Last modified: 2014-01-20

View other active issues in [c.math].

View all other issues in [c.math].

View all issues with Open status.

Discussion:

… and abs(float) and abs(long double). And <cmath> should declare abs(int), abs(long), and abs(long long).

As things currently stand, this program is illegal:

#include <cstdlib>

int main() {
  double d = -1.23;
  double dd = std::abs(d);
  return 0;
}

The call is ambiguous because of the various integer overloads, that's because <cstdlib> provides abs(int) but not abs(double).

This lead one commenter on Stackoverflow to state that abs is dangerous, and to recommend using fabs instead.

In general, it makes sense to declare overloaded functions that take user-defined types in the same header as the definition of the user-defined types; it isn't necessary to declare all of the overloads in the same place. But here we're not dealing with any user-defined types; we're dealing with builtin types, which are always defined; all of the overloads should be defined in the same place, to avoid mysterious problems like the one in the code above.

The standard library has six overloads for abs:

int abs(int);  // <cstdlib>
long abs(long); // <cstdlib>
long long abs(long long); // <cstdlib>

float abs(float); // <cmath>
double abs(double); // <cmath>
long double abs(long double); // <cmath>

These should all be declared in both headers.

I have no opinion on <stdlib.h> and <math.h>.

[2013-09 Chicago]

This issue is related to LWG 2192

Move to open

Proposed resolution:


2295. Locale name when the provided Facet is a nullptr

Section: 22.3.1.2 [locale.cons] Status: New Submitter: Juan Soulie Opened: 2013-09-04 Last modified: 2013-10-15

View all issues with New status.

Discussion:

22.3.1.2 [locale.cons] p14 ends with:

"[…] If f is null, the resulting object is a copy of other."

but the next line p15 says:

"Remarks: The resulting locale has no name."

But both can't be true when other has a name and f is null.

I've tried it on two implementations (MSVC,GCC) and they are inconsistent with each other on this.

Daniel Krügler:

As currently written, the Remarks element applies unconditionally for all cases and thus should "win". The question arises whether the introduction of this element by LWG 424 had actually intended to change the previous Note to a Remarks element. In either case the wording should be improved to clarify this special case.

Proposed resolution:


2296. std::addressof should be constexpr

Section: 20.7.12.1 [specialized.addressof] Status: New Submitter: Daryle Walker Opened: 2013-09-08 Last modified: 2014-01-20

View all other issues in [specialized.addressof].

View all issues with New status.

Discussion:

I'm writing a function that needs to be constexpr and I wanted to take the address of its input. I was thinking of using std::addressof to be safe, but it isn't currently constexpr. A sample implementation couldn't be constexpr under the C++11 rules, though.

Daniel Krügler:

Indeed the core language clarified by CWG 1312 and by CWG 1384, that such emulations of std::addressof implementations are not valid in constant expressions, therefore it seems more like a defect than a feature request to ask for the guarantee that std::addressof is a constexpr function. It should be added that a similar requirement already exists for offsetof indirectly via the C99 standard as of 7.17 p3:

The macros are […]

offsetof(type, member-designator)

which expands to an integer constant expression that has type size_t […]

combined with the noted property in C++11 that:

"offsetof is required to work as specified even if unary operator& is overloaded for any of the types involved"

Therefore implementations should already be able without heroic efforts to realize this functionality by some intrinsic. The wording needs at least to ensure that for any lvalue core constant expression e the expression std::addressof(e) is a core constant expression.

[2013-09 Chicago]

Proposed resolution:

This wording is relative to N3691.

  1. Change header <memory> synopsis, 20.7.2 [memory.syn] as indicated:

    namespace std {
      […]
      // 20.8.12, specialized algorithms:
      template <class T> constexpr T* addressof(T& r) noexcept;
      […]
    }
    
  2. Change 20.7.12.1 [specialized.addressof] as indicated:

    template <class T> constexpr T* addressof(T& r) noexcept;
    

    -1- Returns: The actual address of the object or function referenced by r, even in the presence of an overloaded operator&.

    -?- Remarks: For any lvalue core constant expression e (5.19 [expr.const]), the expression std::addressof(e) is a core constant expression.


2299. [CD] Effects of inaccessible key_compare::is_transparent type are not clear

Section: 23.2.4 [associative.reqmts] Status: Review Submitter: Daniel Krügler Opened: 2013-09-24 Last modified: 2013-10-15

View other active issues in [associative.reqmts].

View all other issues in [associative.reqmts].

View all issues with Review status.

Discussion:

Addresses ES 16

The condition "X::key_compare::is_transparent exists" does not specify that the type be publicly accessible.

Consider the public accessibility of X::key_compare::is_transparent and whether its potential inaccessibility should be banned for a compliant key_compare type.

[2013-09-24 Daniel provides resolution suggestion]

[2013-09-25 Chicago]

Daniel's wording is good, advance to Immediate to respond to NB comment.

[2013-09-26 Chicago]

Moved back to Review as Daniel would like another look at the words, and to confirm implementability.

Proposed resolution:

This wording is relative to N3691.

  1. Add a new definition sub-clause to 23.2.4 [associative.reqmts]:

    ??? [defns.attainable]

    attainable

    A

  2. Change 23.2.4 [associative.reqmts] p8 as indicated:

    -8- In Table 102, X denotes an associative container class, a denotes a value of X, a_uniq denotes a value of X when X supports unique keys, a_eq denotes a value of X when X supports multiple keys, a_tran denotes a value of X when thea publicly accessible type X::key_compare::is_transparent exists whose name is unambiguous and not hidden, […]

  3. Change 23.2.4 [associative.reqmts] p13 as indicated:

    The member function templates find, count, lower_bound, upper_bound, and equal_range shall not participate in overload resolution unless thea publicly accessible type Compare::is_transparent exists whose name is unambiguous and not hidden.


2301. Why is std::tie not constexpr?

Section: 20.4.2.4 [tuple.creation] Status: New Submitter: Rein Halbersma Opened: 2013-09-11 Last modified: 2013-10-15

View all other issues in [tuple.creation].

View all issues with New status.

Discussion:

In N3471, a bunch of routines from header <tuple> were made constexpr.

make_tuple/tuple_cat/get<>(tuple)/relational operators — all these were "constexpr-ified".

But not tie. This is similar to Issue 2275, where the same observation was made about forward_as_tuple.

Proposed resolution:

This wording is relative to N3691.

  1. Change the header <tuple> synopsis, 20.4.1 [tuple.general] p2 as indicated:

    template<class... Types>
      constexpr tuple<Types&...> tie(Types&...) noexcept;
    
  2. Change 20.4.2.4 [tuple.creation] around p7 as indicated:

    template<class... Types>
      constexpr tuple<Types&...> tie(Types&... t) noexcept;
    

2302. Passing null pointer to placement new

Section: 18.6.1.3 [new.delete.placement] Status: New Submitter: Marc Glisse Opened: 2013-09-12 Last modified: 2013-10-15

View other active issues in [new.delete.placement].

View all other issues in [new.delete.placement].

View all issues with New status.

Discussion:

Based on this discussion and as discussed in c++std-core-23998 and c++std-lib-34442, calling placement new currently forces the compiler to check if the pointer is null before initializing the object (a non-negligible cost). It seems many people were not aware of this and they consider it a user error to pass a null pointer to it.

Proposed resolution: for operator new and operator new[], add:

Requires: ptr shall not be a null pointer.

Proposed resolution:

This wording is relative to N3691.

  1. Change 18.6.1.3 [new.delete.placement] as indicated:

    void* operator new(std::size_t size, void* ptr) noexcept;
    

    -?- Requires: ptr shall not be a null pointer.

    -2- Returns: ptr.

    -3- Remarks: Intentionally performs no other action.

    -4- [Example: This can be useful for constructing an object at a known address:

    void* place = operator new(sizeof(Something));
    Something* p = new (place) Something();
    

    end example]

    void* operator new[](std::size_t size, void* ptr) noexcept;
    

    -?- Requires: ptr shall not be a null pointer.

    -5- Returns: ptr.

    -6- Remarks: Intentionally performs no other action.


2303. Explicit instantiation of std::vector<UserType> broken?

Section: 18.6.1.3 [new.delete.placement] Status: New Submitter: Daniel Krügler Opened: 2013-09-18 Last modified: 2013-11-28

View other active issues in [new.delete.placement].

View all other issues in [new.delete.placement].

View all issues with New status.

Discussion:

The library gives explicit permission in 17.6.4.2.1 [namespace.std] p2 that user code may explicitly instantiate a library template provided that the instantiations depend on at least one user-defined type:

A program may explicitly instantiate a template defined in the standard library only if the declaration depends on the name of a user-defined type and the instantiation meets the standard library requirements for the original template.

But it seems that the C++11 library is not specified in a way that guarantees such an instantiation to be well-formed if the minimum requirements of the library is not satisfied.

For example, in general, the first template parameter of std::vector is not required to be DefaultConstructible in general, but due to the split of the single C++03 member function with default argument

void resize(size_type sz, T c = T());

into

void resize(size_type sz);
void resize(size_type sz, const T& c);

the effect is now that for a type ND that is not DefaultConstructible, such as

struct NP { 
  NP(int); 
};

the explicit instantiation of std::vector<ND> is no longer well-formed, because the attempt to instantiate the single-argument overload of resize cannot not succeed, because this function imposes the DefaultInsertable requirements and given the default allocator this effectively requires DefaultConstructible.

But DefaultConstructible is not the only point, what about CopyConstructible versus MoveConstructible alone? It turns out that currently the second resize overload would fail during an explicit instantiation for a type like

struct MO { 
  MO() = default; 
  MO(MO&&) = default; 
};

because it imposes CopyInsertable requirements that end up being equivalent to the CopyConstructible requirements for the default allocator.

Technically a library can solve these issues: For special member functions by defining them in some base class, for others by transforming them effectively into a function template due to the great feature of default template arguments for function templates (At the very moment the validity of the latter approach depends on a resolution of core language issue CWG 1635, though). E.g. the here mentioned resize functions of std::vector could be prevented from instantiation by defining them like this with an implementation:

template<class = void>
void resize(size_type sz) { […] }
template<class = void>
void resize(size_type sz, const T& c) { […] }

In this case, these functions could also be defined in a base class, but the latter approach won't work in all cases.

Basically such an implementation is required to constrain all member functions that are not covered by the general requirements imposed on the actual library template parameters. I tested three different C++11 library implementations and but none could instantiate for example std::list, std::vector, or std::deque with value types that are not DefaultConstructible or only MoveConstructible.

This issue is raised to clarify the current situation in regard to the actual requirements imposed on user-provided types that are used to explicitly instantiate Library-provided templates. For example, the current Container requirements impose very little requirements on the actual value type and it is unclear to which extend library implementations have to respect that.

The minimum solution of this issue should be to at least realize that there is no fundamental requirement on DefaultConstructible for value types of library containers, because we have since C++03 the general statement of 17.6.3.1 [utility.arg.requirements] ("In general, a default constructor is not required."). It is unclear whether CopyConstructible should be required for an explicit instantiation request, but given the careful introduction of move operations in the library it would seem astonishing that a MoveConstructible type wouldn't suffice for value types of the container types.

In any case I can envision at least two approaches to solve this issue:

  1. As indicated in LWG 2292, those function could get an explicit "Template Constraints:" element, albeit this promises more than needed to solve this issue.

  2. The library could introduce a completely new element form, such as "Instantiation Constraints:" that would handle this situation for explicit instantiation situations. This would allow for simpler techniques to solve the issue when explicit instantiation is required compared to the first bullet, because it would not (necessarily) guarantee SFINAE-friendly expression-wellformedness, such as inspecting the expression std::declval<std::vector<ND>&>.resize(0) in an unevaluated context.

It should be noted that the 2013-08-27 comment to LWG 2193 could be resolved by a similar solution as indicated in this issue here.

Proposed resolution:


2304. Complexity of count in unordered associative containers

Section: 23.2.5 [unord.req] Status: New Submitter: Joaquín M López Muñoz Opened: 2013-09-20 Last modified: 2013-10-15

View other active issues in [unord.req].

View all other issues in [unord.req].

View all issues with New status.

Discussion:

Table 103 in 23.2.5 [unord.req] states that the complexity of b.count(k) is average case 𝒪(1) rather than linear with the number of equivalent elements, which seems to be a typo as this requires holding an internal count of elements in each group of equivalent keys, something which hardly looks the intent of the standard and no (known by the submitter) stdlib implementation is currently doing.

Proposed resolution:

This wording is relative to N3691.

  1. Change Table 103 as indicated:

    Table 103 — Unordered associative container requirements (in addition to container)
    Expression Return type Assertion/note pre-/post-condition Complexity
    b.count(k) size_type Returns the number of elements with key equivalent to k. Average case 𝒪(1b.count(k)), worst case 𝒪(b.size()).

2305. optional forwarding construction/assignment

Section: X [optional.object.ctor] Status: Deferred Submitter: Cassio Neri Opened: 2013-09-23 Last modified: 2013-10-15

View all issues with Deferred status.

Discussion:

Consider:

struct foo {
  foo(std::initializer_list<int>&);        // 1
  foo(const std::initializer_list<int>&);  // 2
  foo(std::initializer_list<int>&&);       // 3
  foo(const std::initializer_list<int>&&); // 4
};

std::initializer_list<int> il{0, 1, 2};

foo foo_0{1, 2, 3};                                 // calls 3
foo foo_1{il};                                      // calls 1
foo foo_2((const std::initializer_list<int>&) il);  // calls 2
foo foo_3{(std::initializer_list<int>&&) il};       // calls 3
foo foo_4((const std::initializer_list<int>&&) il); // calls 4

Although the constructors of foo are unusual (initializer_lists are normally passed by value) users of optional could naturally expect perfect forwarding of initializer_lists. However, all lines below end up calling 1.

optional<foo> opt0{in_place, {1, 2, 3}};
optional<foo> opt1{in_place, il};                    
optional<foo> opt3{in_place, (const std::initializer_list<int>&) il};
optional<foo> opt2{in_place, (std::initializer_list<int>&&) il};
optional<foo> opt4{in_place, (const std::initializer_list<int>&&) il};

opt0.emplace({1, 2, 3});
opt0.emplace(il);
opt0.emplace((const std::initializer_list<int>&) il);
opt0.emplace((std::initializer_list<int>&&) il);
opt0.emplace((const std::initializer_list<int>&&) il);

The constructor

template <class... Args> constexpr explicit optional(in_place_t, Args&&... args);

can handle all constructor calls above, except the one taking {1, 2, 3}. Hence, a simple modification of

template <class U, class... Args>
constexpr explicit optional(in_place_t, initializer_list<U>&& il, Args&&... args);

allows perfect forwarding of std::initializer_list<U>s to be complete.

Proposed resolution:

This wording is relative to N3691.

  1. Change X [optional.object.ctor] as indicated:

    template <class U, class... Args> 
    constexpr explicit optional(in_place_t, initializer_list<U>&& il, Args&&... args);
    

    -27- Requires: is_constructible<T, initializer_list<U>&&, Args&&...>::value is true.

    -28- Effects: Initializes the contained value as if constructing an object of type T with the arguments ilstd::move(il), std::forward<Args>(args)....

    […]

    -31- Remarks: The function shall not participate in overload resolution unless is_constructible<T, initializer_list<U>&, Args&&...>::value is true.

  2. Change X [optional.object.assign] as indicated:

    template <class U, class... Args>
    void optional<T>::emplace(initializer_list<U>&& il, Args&&... args);
    

    -27- Requires: is_constructible<T, initializer_list<U>&&, Args&&...>::value is true.

    -28- Effects: Calls *this = nullopt. Then initializes the contained value as if constructing an object of type T with the arguments ilstd::move(il), std::forward<Args>(args)....

    […]

    -32- Remarks: This function shall not participate in overload resolution unless is_constructible<T, initializer_list<U>&, Args&&...>::value is true.


2306. match_results::reference should be value_type&, not const value_type&

Section: 28.10 [re.results] Status: New Submitter: Matt Austern Opened: 2013-09-25 Last modified: 2013-11-28

View other active issues in [re.results].

View all other issues in [re.results].

View all issues with New status.

Discussion:

The match_results class synopsis has

typedef const value_type& const_reference;
typedef const_reference reference;

We're getting too enthusiastic about types here by insisting that reference is a const reference, even though match_results is a read-only container. In the container requirements table (Table 96, in section 23.2.1 [container.requirements.general] we say that Container::reference is "lvalue of T" and Container::const_reference is "const lvalue of T".

That phrasing in the container requirements table is admittedly a little fuzzy and ought to be clarified (as discussed in lwg issue 2182), but in context it's clear that Container::reference ought to be a T& even for constant containers. In the rest of Clause 23 we see that Container::reference is T&, not const T&, even for const-qualified containers and that it's T&, not const T&, even for containers like set and unordered_set that provide const iterators only.

The way we handle const containers is just that in the case of a const-qualified container (including match_results) there are no operations that return Container::reference. That's already the case, so this issue is complaining about an unused typedef.

[2013-10-17: Daniel comments]

The std::initializer_list synopsis, 18.9 [support.initlist] shows a similar problem:

template<class E> class initializer_list {
public:
  typedef E value_type;
  typedef const E& reference;
  typedef const E& const_reference;
  […]
}

Given the fact that std::initializer_list doesn't meet the container requirements anyway (and is such a core-language related type) I recommend to stick with the current state.

Proposed resolution:

This wording is relative to N3691.

  1. Change the class template match_results header synopsis, 28.10 [re.results] p4 as indicated:

    typedef const value_type& const_reference;
    typedef const_referencevalue_type& reference;
    

2307. Should the Standard Library use explicit only when necessary?

Section: 23 [containers] Status: New Submitter: Zhihao Yuan Opened: 2013-09-26 Last modified: 2013-10-15

View other active issues in [containers].

View all other issues in [containers].

View all issues with New status.

Discussion:

LWG 2193 yields explicit for default ctors to allow {}, but not for all cases of uniform initialization. For example:

explicit vector(size_type count, const Allocator& alloc = Allocator());

This prevents {n, alloc()}. Although this use is relatively rare, but the behavior is inconsistent with that of

vector(size_type count, const T& value, const Allocator& alloc = Allocator());

Proposed resolution:


2308. Clarify container destructor requirements w.r.t. std::array

Section: 23.2.1 [container.requirements.general] Status: New Submitter: Jonathan Wakely Opened: 2013-09-26 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with New status.

Discussion:

It has been suggested that Table 96 — "Container requirements" makes confusing requirements for the destructor of std::array:

"note: the destructor is applied to every element of a; all the memory is deallocated."

Since std::array obtains no memory, there is none to deallocate, arguably making it unclear what the requirement means for std::array::~array().

Proposed resolution:

This wording is relative to N3691.

  1. Change in 23.2.1 [container.requirements.general], Table 96 — "Container requirements", the "Assertion/note/pre-/post-condition" for the expression "(&a)->~X()" as indicated:

    note: the destructor is applied to every element of a; all theany memory obtained is deallocated.


2309. mutex::lock() should not throw device_or_resource_busy

Section: 30.4.1.2 [thread.mutex.requirements.mutex] Status: New Submitter: Detlef Vollmann Opened: 2013-09-27 Last modified: 2013-10-15

View other active issues in [thread.mutex.requirements.mutex].

View all other issues in [thread.mutex.requirements.mutex].

View all issues with New status.

Discussion:

As discussed during the Chicago meeting in SG1 the only reasonable reasons for throwing device_or_resource_busy seem to be:

Proposed resolution:


2310. Public exposition only member in std::array

Section: 23.3.2.1 [array.overview] Status: New Submitter: Jonathan Wakely Opened: 2013-09-30 Last modified: 2013-10-15

View all issues with New status.

Discussion:

23.3.2.1 [array.overview] shows std::array with an "exposition only" data member, elems.

The wording in 17.5.2.3 [objects.within.classes] that defines how "exposition only" is used says it applies to private members, but std::array::elems (or its equivalent) must be public in order for std::array to be an aggregate.

If the intention is that std::array::elems places requirements on the implementation to provide "equivalent external behavior" to a public array member, then 17.5.2.3 [objects.within.classes] needs to cover public members too, or some other form should be used in 23.3.2.1 [array.overview].

Proposed resolution:


2311. Allocator requirements should be further minimized

Section: 17.6.3.5 [allocator.requirements] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [allocator.requirements].

View all other issues in [allocator.requirements].

View all issues with New status.

Discussion:

C++11's minimized allocator requirements are great, but they're still requiring more things from users than absolutely necessary.

Proposed resolution:

This wording is relative to N3691.

  1. Change in 17.6.3.5 [allocator.requirements], Table 28 — "Allocator requirements" as indicated:

    Table 28 — Allocator requirements (continued)
    Expression Return type Assertion/note pre-/post-condition Default
    X::value_type Identical to T   See Note B, below.
    a1 == a2 bool returns true only if storage
    allocated from each can be
    deallocated via the other.
    operator== shall be reflexive,
    symmetric, and transitive, and
    shall not exit via an exception.
    true
    a1 != a2 bool same as !(a1 == a2)  
    a == b bool same as a ==
    Y::rebind<T>::other(b)
     
    a != b bool same as !(a == b)  
    X a(b);   Shall not exit via an exception.
    post: Y(a) == b, a == X(b)
     
    X a(move(b));   Shall not exit via an exception.
    post: a equals the prior value of X(b).
     
  2. After 17.6.3.5 [allocator.requirements] p3, add a new paragraph:

    Note B: If Allocator is a class template instantiation of the form SomeAllocator<T, Args>, where Args is zero or more type arguments, and Allocator does not supply a nested type named value_type, the standard allocator_traits template uses T in place of Allocator::value_type by default. For allocator types that are not template instantiations of the above form, no default is provided.

  3. In the example provided in 17.6.3.5 [allocator.requirements]/5, delete as indicated:

    template <class Tp>
    struct SimpleAllocator {
      typedef Tp value_type;
      SimpleAllocator(ctor args);
      template <class T> SimpleAllocator(const SimpleAllocator<T>& other);
      Tp *allocate(std::size_t n);
      void deallocate(Tp *p, std::size_t n);
    };
    
    template <class T, class U>
    bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
    template <class T, class U>
    bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
    
  4. Edit 20.7.8 [allocator.traits]p1, class template allocator_traits synopsis, as indicated:

    namespace std {
      template <class Alloc> struct allocator_traits {
        typedef Alloc allocator_type;
    
        typedef typename Alloc::value_typesee below value_type;
    
        […]
    
        static Alloc select_on_container_copy_construction(const Alloc& rhs);
    
        static bool equal(const Alloc& a1, const Alloc& a2) noexcept;
      };
    }
    
  5. At the beginning of 20.7.8.1 [allocator.traits.types], add a new paragraph:

    typedef see below value_type;
    

    Type: Alloc::value_type if such a type exists; otherwise, T if Alloc is a class template instantiation of the form Alloc<T, Args>, where Args is zero or more type arguments; otherwise, the program is ill-formed.

  6. At the end of 20.7.8.2 [allocator.traits.members], add a new paragraph:

    static bool equal(const Alloc& a1, const Alloc& a2) noexcept;
    

    -?- Returns: a1 == a2 if that expression is well-formed; otherwise, true.


2312. tuple's constructor constraints need to be phrased more precisely

Section: 20.4.2.1 [tuple.cnstr] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all other issues in [tuple.cnstr].

View all issues with New status.

Discussion:

Consider the following code:

void meow(tuple<long, long>) { puts("Two"); }

void meow(tuple<long, long, long>) { puts("Three"); }

tuple<int, int, int> t(0, 0, 0);

meow(t);

This should compile and print "Three" because tuple<long, long>'s constructor from const tuple<int, int, int>& should remove itself from overload resolution. Implementations sensibly do this, but the Standard doesn't actually say it!

In this case, Types is "long, long" and UTypes is "int, int, int". 20.4.2.1 [tuple.cnstr]/3 says "let i be in the range [0,sizeof...(Types)) in order", which is [0, 2). Then /17 says "Remark: This constructor shall not participate in overload resolution unless const Ui& is implicitly convertible to Ti for all i." Interpreted literally, this is true! /15 says "Requires: sizeof...(Types) == sizeof...(UTypes)." but requiring the sizes to be identical doesn't help. Only the special phrase "shall not participate in overload resolution unless" mandates SFINAE/enable_if machinery.

The wording that we need is almost available in the Requires paragraphs, except that the Requires paragraphs say "is_constructible" while the Remark paragraphs say "is implicitly convertible", which is the correct thing for the SFINAE constraints to check. My proposed resolution is to unify the Requires and Remark paragraphs, after which there will be no need for Requires (when a constructor participates in overload resolution if and only if X is true, then there's no need for it to Require that X is true).

Note: 20.10.4.3 [meta.unary.prop]/6 specifies is_constructible<To, From> and 20.10.6 [meta.rel]/4 specifies is_convertible<From, To>. Both are specified in terms of "template <class T> typename add_rvalue_reference<T>::type create();". Therefore, passing From and From&& is equivalent, regardless of whether From is an object type, an lvalue reference, or an rvalue reference.

Also note that 20.4.2.1 [tuple.cnstr]/3 defines T0 and T1 so we don't need to repeat their definitions.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 20.4.2.1 [tuple.cnstr] as indicated:

    template <class... UTypes>
      explicit constexpr tuple(UTypes&&... u);
    

    -8- Requires: sizeof...(Types) == sizeof...(UTypes). is_constructible<Ti, Ui&&>::value is true for all i.

    […]

    -10- Remark: This constructor shall not participate in overload resolution unless each type in UTypes is implicitly convertible to its corresponding type in Typessizeof...(Types) == sizeof...(UTypes) and both is_constructible<Ti, Ui>::value and is_convertible<Ui, Ti>::value are true for all i.

    […]

    template <class... UTypes>
      constexpr tuple(const tuple<UTypes...>& u);
    

    -15- Requires: sizeof...(Types) == sizeof...(UTypes). is_constructible<Ti, const Ui&>::value is true for all i.

    […]

    -17- Remark: This constructor shall not participate in overload resolution unless const Ui& is implicitly convertible to Tisizeof...(Types) == sizeof...(UTypes) and both is_constructible<Ti, const Ui&>::value and is_convertible<const Ui&, Ti>::value are true for all i.

    template <class... UTypes>
      constexpr tuple(tuple<UTypes...>&& u);
    

    -18- Requires: sizeof...(Types) == sizeof...(UTypes). is_constructible<Ti, Ui&&>::value is true for all i.

    […]

    -20- Remark: This constructor shall not participate in overload resolution unless each type in UTypes is implicitly convertible to its corresponding type in Typessizeof...(Types) == sizeof...(UTypes) and both is_constructible<Ti, Ui>::value and is_convertible<Ui, Ti>::value are true for all i.

    template <class U1, class U2> constexpr tuple(const pair<U1, U2>& u);
    

    -21- Requires: sizeof...(Types) == 2. is_constructible<T0, const U1&>::value is true for the first type T0 in Types and is_constructible<T1, const U2&>::value is true for the second type T1 in Types.

    […]

    -23- Remark: This constructor shall not participate in overload resolution unless const U1& is implicitly convertible to T0 and const U2& is implicitly convertible to T1sizeof...(Types) == 2 && is_constructible<T0, const U1&>::value && is_constructible<T1, const U2&>::value && is_convertible<const U1&, T0>::value && is_convertible<const U2&, T1>::value is true.

    template <class U1, class U2> constexpr tuple(pair<U1, U2>&& u);
    

    -24- Requires: sizeof...(Types) == 2. is_constructible<T0, U1&&>::value is true for the first type T0 in Types and is_constructible<T1, U2&&>::value is true for the second type T1 in Types.

    […]

    -26- Remark: This constructor shall not participate in overload resolution unless U1 is implicitly convertible to T0 and U2 is implicitly convertible to T1sizeof...(Types) == 2 && is_constructible<T0, U1>::value && is_constructible<T1, U2>::value && is_convertible<U1, T0>::value && is_convertible<U2, T1>::value is true.


2313. tuple_size should always derive from integral_constant<size_t, N>

Section: 20.4.2.5 [tuple.helper] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all other issues in [tuple.helper].

View all issues with New status.

Discussion:

In 20.4.2.5 [tuple.helper], the "primary template" is depicted as:

template <class... Types>
class tuple_size<tuple<Types...> >
  : public integral_constant<size_t, sizeof...(Types)> { };

However, 20.3.4 [pair.astuple]/1-2 and 23.3.2.9 [array.tuple]/1-2 are underspecified, saying:

tuple_size<pair<T1, T2> >::value

Returns: Integral constant expression.

Value: 2.

tuple_size<array<T, N> >::value

Return type: integral constant expression.

Value: N

They should be required to behave like the "primary template". This is more than a stylistic decision — it allows tuple_size to be passed to a function taking integral_constant.

LWG 1118 noticed this underspecification, but instead of correcting it, the resolution changed 20.4.2.5 [tuple.helper]/3 to require tuple_size<cv T> to derive from integral_constant<remove_cv<decltype(TS::value)>::type, TS::value>. This is unnecessarily overgeneralized. tuple_size is primarily for tuples, where it is required to be size_t, and it has been extended to handle pairs and arrays, which (as explained above) should also be guaranteed to be size_t. tuple_size<cv T> works with cv-qualified tuples, pairs, arrays, and user-defined types that also want to participate in the tuple_size system. It would be far simpler and perfectly reasonable to expect that user-defined types supporting the "tuple-like protocol" should have tuple_sizes of size_t.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 20.3.4 [pair.astuple]/1-2 as indicated:

    tuple_size<pair<T1, T2> >::value
    template <class T1, class T2>
    struct tuple_size<pair<T1, T2>>
      : integral_constant<size_t, 2> { };
    

    -1- Returns: Integral constant expression.

    -2- Value: 2.

  2. Edit 23.3.2.9 [array.tuple]/1-2 as indicated:

    tuple_size<array<T, N> >::value
    template <class T, size_t N>
    struct tuple_size<array<T, N>>
      : integral_constant<size_t, N> { };
    

    -1- Returns: Integral constant expression.

    -2- Value: N.

  3. Edit 20.4.2.5 [tuple.helper]/p1-p3 as indicated:

    template <class T> struct tuple_size;
    

    -?- Remarks: All specializations of tuple_size<T> shall meet the UnaryTypeTrait requirements (20.10.1 [meta.rqmts]) with a BaseCharacteristic of integral_constant<size_t, N> for some N.

    template <class... Types>
    struct tuple_size<tuple<Types...> >
      : integral_constant<size_t, sizeof...(Types)> { };
      
    template <size_t I, class... Types>
    class tuple_element<I, tuple<Types...> > {
    public:
      typedef TI type;
    };
    

    -1- Requires: I < sizeof...(Types). The program is ill-formed if I is out of bounds.

    […]

    template <class T> class tuple_size<const T>;
    template <class T> class tuple_size<volatile T>;
    template <class T> class tuple_size<const volatile T>;
    

    -3- Let TS denote tuple_size<T> of the cv-unqualified type T. Then each of the three templates shall meet the UnaryTypeTrait requirements (20.10.1 [meta.rqmts]) with a BaseCharacteristic of

    integral_constant<remove_cv<decltype(TS::value)>::typesize_t, TS::value>
    

2314. apply() should return decltype(auto) and use decay_t before tuple_size

Section: 20.5.1 [intseq.general] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all issues with New status.

Discussion:

The example in 20.5.1 [intseq.general]/2 depicts apply_impl() and apply() as returning auto. This is incorrect because it will trigger decay and will not preserve F's return type. For example, if invoking the functor returns const int&, apply_impl() and apply() will return int. decltype(auto) should be used for "perfect returning".

Additionally, this depicts apply() as taking Tuple&&, then saying "std::tuple_size<Tuple>::value". This is incorrect because when apply() is called with lvalue tuples, perfect forwarding will deduce Tuple to be cv tuple&, but 20.4.2.5 [tuple.helper] says that tuple_size handles only cv tuple, not references to tuples. Using remove_reference_t would avoid this problem, but so would decay_t, which has a significantly shorter name. (The additional transformations that decay_t does are neither beneficial nor harmful here.)

Proposed resolution:

This wording is relative to N3691.

  1. Edit the example code in 20.5.1 [intseq.general]/2 as indicated:

    template<class F, class Tuple, std::size_t... I>
      autodecltype(auto) apply_impl(F&& f, Tuple&& t, index_sequence<I...>) {
        return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
      }
    template<class F, class Tuple>
      autodecltype(auto) apply(F&& f, Tuple&& t) {
        using Indices = make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>;
        return apply_impl(std::forward<F>(f), std::forward<Tuple>(t), Indices());
      }
    

2315. weak_ptr should be movable

Section: 20.8.2.3 [util.smartptr.weak] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all other issues in [util.smartptr.weak].

View all issues with New status.

Discussion:

Like shared_ptr, weak_ptr should be movable to avoid unnecessary atomic increments/decrements of the weak refcount.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 20.8.2.3 [util.smartptr.weak]/1, class template weak_ptr synopsis, as indicated:

    namespace std {
      template<class T> class weak_ptr {
      public:
        typedef T element_type;
    
        // 20.9.2.3.1, constructors
        constexpr weak_ptr() noexcept;
        template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
        weak_ptr(weak_ptr const& r) noexcept;
        template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
        weak_ptr(weak_ptr&& r) noexcept;
        template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
    
        […]
    
        // 20.9.2.3.3, assignment
        weak_ptr& operator=(weak_ptr const& r) noexcept;
        template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
        template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
        weak_ptr& operator=(weak_ptr&& r) noexcept;
        template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
      };
    }
    
  2. Add the following new paragraphs at the end of sub-clause 20.8.2.3.1 [util.smartptr.weak.const]:

    weak_ptr(weak_ptr&& r) noexcept;
    template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
    

    -?- Remark: The second constructor shall not participate in overload resolution unless Y* is implicitly convertible to T*.

    -?- Effects: Move-constructs a weak_ptr instance from r.

    -?- Postconditions: *this shall contain the old value of r. r shall be empty. r.use_count() == 0.

  3. Edit 20.8.2.3.3 [util.smartptr.weak.assign] as indicated:

    weak_ptr& operator=(const weak_ptr& r) noexcept;
    template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
    template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
    

    -1- Effects: […]

    -2- Remarks: […]

    -?- Returns: *this.

    weak_ptr& operator=(weak_ptr&& r) noexcept;
    template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
    

    -?- Effects: Equivalent to weak_ptr(std::move(r)).swap(*this).

    -?- Returns: *this.


2316. weak_ptr::lock() should be atomic

Section: 20.8.2.3.5 [util.smartptr.weak.obs] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all other issues in [util.smartptr.weak.obs].

View all issues with New status.

Discussion:

20.8.2.2 [util.smartptr.shared]/4 says: "For purposes of determining the presence of a data race, member functions shall access and modify only the shared_ptr and weak_ptr objects themselves and not objects they refer to. Changes in use_count() do not reflect modifications that can introduce data races." This requires shared_ptr/weak_ptr implementations to protect their strong and weak refcounts with atomic operations, without the Standardese having to say this elsewhere. However, 20.8.2.3.5 [util.smartptr.weak.obs]/5 describes weak_ptr::lock() with "Returns: expired() ? shared_ptr<T>() : shared_ptr<T>(*this)." Even after considering the blanket wording about data races, this specification is insufficient. If this conditional expression were literally implemented, the use_count() could change from nonzero to zero after testing expired(), causing shared_ptr<T>(*this) to throw bad_weak_ptr when the intention is for weak_ptr::lock() to return empty or nonempty without throwing — indeed, weak_ptr::lock() is marked as noexcept.

We all know what weak_ptr::lock() should do, the Standardese just doesn't say it. shared_ptr(const weak_ptr<Y>&)'s specification is not really affected because 20.8.2.2.1 [util.smartptr.shared.const]/23-27 describes the behavior with English instead of code.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 20.8.2.3.5 [util.smartptr.weak.obs]/5 as indicated:

    shared_ptr<T> lock() const noexcept;
    

    -5- Returns: expired() ? shared_ptr<T>() : shared_ptr<T>(*this), executed atomically.


2317. The type property queries should be UnaryTypeTraits returning size_t

Section: 20.10.5 [meta.unary.prop.query] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all issues with New status.

Discussion:

The sibling sections 20.10.4 [meta.unary], 20.10.6 [meta.rel], and 20.10.7 [meta.trans] respectively specify UnaryTypeTraits, BinaryTypeTraits, and TransformationTraits, as stated by each /2 paragraph. However, 20.10.5 [meta.unary.prop.query] is underspecified. alignment_of, rank, and extent are said to produce "Values", but the type of that Value is not specified, and the struct templates are not required to derive from integral_constant. Such derivation is more than stylistic — it allows the structs to be passed to functions taking integral_constant.

alignment_of returns alignof(T) which is size_t (5.3.6 [expr.alignof]/2). extent returns an array bound, which is clearly size_t. rank returns "the number of dimensions" of an array, so any type could be chosen, with size_t being a reasonable choice. (Another choice would be unsigned int, to match extent's template parameter I.)

Proposed resolution:

This wording is relative to N3691.

  1. Following 20.10.5 [meta.unary.prop.query]/1 add a new paragraph as indicated:

    Each of these templates shall be a UnaryTypeTrait (20.10.1 [meta.rqmts]) with a BaseCharacteristic of integral_constant<size_t, Value>.


2318. basic_string's wording has confusing relics from the copy-on-write era

Section: 21.4 [basic.string] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [basic.string].

View all other issues in [basic.string].

View all issues with New status.

Discussion:

21.4.4 [string.capacity]/8 specifies basic_string::resize(n, c) with:

Effects: Alters the length of the string designated by *this as follows:

This wording is a relic of the copy-on-write era. In addition to being extremely confusing, it has undesirable implications. Saying "replaces the string designated by *this with a string of length n whose elements are a copy" suggests that the trimming case can reallocate. Reallocation during trimming should be forbidden, like vector.

At least 7 paragraphs are affected: 21.4.4 [string.capacity]/8, 21.4.6.2 [string::append]/9, 21.4.6.3 [string::assign]/3 and /10, 21.4.6.4 [string::insert]/11, 21.4.6.5 [string::erase]/4, and 21.4.6.6 [string::replace]/11 say "replaces the string [designated/controlled] by *this". (21.4.6.7 [string::copy]/3 is different — it "replaces the string designated by s".)

Of the affected paragraphs, resize() and erase() are the most important to fix because they should forbid reallocation during trimming.

Proposed resolution:


2319. basic_string's move constructor should not be noexcept

Section: 21.4.2 [string.cons] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all other issues in [string.cons].

View all issues with New status.

Discussion:

In debugging implementations, containers (including basic_string) may need to own dynamically allocated helper objects at all times, including in their default-constructed and moved-from states. This means that their default constructors and move constructors may throw exceptions. Therefore, the Standard should not mark them as noexcept. (Other implementations will still be permitted to add noexcept.)

Proposed resolution:

This wording is relative to N3691.

  1. In 21.4 [basic.string]/5, class template basic_string synopsis, and 21.4.2 [string.cons]/2 change as indicated:

    basic_string(basic_string&& str) noexcept;
    
  2. Edit 21.4.2 [string.cons]/17 as indicated:

    basic_string(const basic_string& str, const Allocator& alloc);
    basic_string(basic_string&& str, const Allocator& alloc);
    

    […]

    -17- Throws: The second form throws nothing if alloc == str.get_allocator()..


2320. select_on_container_copy_construction() takes allocators, not containers

Section: 23.2.1 [container.requirements.general] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with New status.

Discussion:

23.2.1 [container.requirements.general]/7 says "Copy constructors for these container types obtain an allocator by calling allocator_traits<allocator_type>::select_on_container_copy_construction on their first parameters." However, 20.7.8.2 [allocator.traits.members]/8 says that this takes const Alloc&, not a container. 23.2.1 [container.requirements.general]/7 goes on to say "Move constructors obtain an allocator by move construction from the allocator belonging to the container being moved." so we can follow that wording.

Proposed resolution:

This wording is relative to N3691.

  1. In 23.2.1 [container.requirements.general]/7 change as indicated:

    -7- Unless otherwise specified, all containers defined in this clause obtain memory using an allocator (see 17.6.3.5). Copy constructors for these container types obtain an allocator by calling allocator_traits<allocator_type>::select_on_container_copy_construction on their first parametersthe allocator belonging to the container being copied. Move constructors obtain an allocator by move construction from the allocator belonging to the container being moved. […]


2321. Moving containers should (usually) be required to preserve iterators

Section: 23.2.1 [container.requirements.general] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [container.requirements.general].

View all other issues in [container.requirements.general].

View all issues with New status.

Discussion:

23.2.1 [container.requirements.general]/10 says that unless otherwise specified, "no swap() function invalidates any references, pointers, or iterators referring to the elements of the containers being swapped. [Note: The end() iterator does not refer to any element, so it may be invalidated. — end note]". However, move constructors and move assignment operators aren't given similar invalidation guarantees. The guarantees need several exceptions, so I do not believe that blanket language like /11 "Unless otherwise specified (either explicitly or by defining a function in terms of other functions), invoking a container member function or passing a container as an argument to a library function shall not invalidate iterators to, or change the values of, objects within that container." is applicable.

Proposed resolution:

This wording is relative to N3691.

  1. In 23.2.1 [container.requirements.general]/10 change as indicated:

    -10- Unless otherwise specified (see 23.2.4.1, 23.2.5.1, 23.3.3.4, and 23.3.7.5) all container types defined in this Clause meet the following additional requirements:

    • […]

    • no copy constructor or assignment operator of a returned iterator throws an exception.

    • no move constructor (or move assignment operator when allocator_traits<allocator_type>::propagate_on_container_move_assignment::value is true) of a container (except for array) invalidates any references, pointers, or iterators referring to the elements of the source container. [Note: The end() iterator does not refer to any element, so it may be invalidated. — end note]

    • no swap() function throws an exception.

    • no swap() function invalidates any references, pointers, or iterators referring to the elements of the containers being swapped. [Note: The end() iterator does not refer to any element, so it may be invalidated. — end note]


2322. Associative(initializer_list, stuff) constructors are underspecified

Section: 23.2.4 [associative.reqmts], 23.2.5 [unord.req] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [associative.reqmts].

View all other issues in [associative.reqmts].

View all issues with New status.

Discussion:

23.2.4 [associative.reqmts] specifies both X(i,j) and X(i,j,c), but only X(il). 23.4.4.1 [map.overview] declares "map(initializer_list<value_type>, const Compare& = Compare(), const Allocator& = Allocator());" but 23.4.4.2 [map.cons] intentionally doesn't explain it, relying on the big table's requirements. As a result, map(il, c)'s behavior is not actually specified by the Standard. (All of the other ordered associative containers also provide such constructors.)

The unordered associative containers are similarly affected, although they have more arguments. (Again, the actual containers are correctly depicted with the desired constructors, their behavior just isn't specified.)

Proposed resolution:

This wording is relative to N3691.

  1. Edit 23.2.4 [associative.reqmts], Table 102 — "Associative container requirements", as indicated:

    Table 102 — Associative container requirements (in addition to container) (continued)
    Expression Return type Assertion/note pre-/post-condition Complexity
    X(il, c);   Same as X(il.begin(), il.end(), c). Same as X(il.begin(), il.end(), c).
    X(il); Same as X(il.begin(), il.end()). sSame as X(il.begin(), il.end()).
  2. Edit 23.2.5 [unord.req], Table 103 "Unordered associative container requirements", as indicated:

    Table 103 — Unordered associative container requirements (in addition to container)
    Expression Return type Assertion/note pre-/post-condition Complexity
    X(il) X Same as X(il.begin(), il.end()). Same as X(il.begin(), il.end()).
    X(il, n) X Same as X(il.begin(), il.end(), n). Same as X(il.begin(), il.end(), n).
    X(il, n, hf) X Same as X(il.begin(), il.end(), n, hf). Same as X(il.begin(), il.end(), n, hf).
    X(il, n, hf, eq) X Same as X(il.begin(), il.end(), n, hf, eq). Same as X(il.begin(), il.end(), n, hf, eq).

2323. vector::resize(n, t)'s specification should be simplified

Section: 23.3.6.3 [vector.capacity], 23.3.3.3 [deque.capacity] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [vector.capacity].

View all other issues in [vector.capacity].

View all issues with New status.

Discussion:

First, 23.3.3.3 [deque.capacity]/4 and 23.3.6.3 [vector.capacity]/16 say that resize(size_type sz, const T& c) "Requires: T shall be MoveInsertable into *this and CopyInsertable into *this." The CopyInsertable requirement is correct (because sz might be size() + 2 or more), but the MoveInsertable requirement is redundant due to 23.2.1 [container.requirements.general]/13: "T is CopyInsertable into X means that, in addition to T being MoveInsertable into X, the [...]". (LWG 2033's resolution said that this was "not redundant, because CopyInsertable is not necessarily a refinement of MoveInsertable" which was true at the time, but then LWG 2177's resolution made it a refinement.)

Second, 23.3.6.3 [vector.capacity]/17 says "Remarks: If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects." This is confusing because T is required to be CopyInsertable. (/14 says the same thing for resize(size_type sz), where it is correct because that overload requires only MoveInsertable and DefaultInsertable.)

Proposed resolution:

This wording is relative to N3691.

  1. Edit 23.3.3.3 [deque.capacity]/4 as indicated:

    void resize(size_type sz, const T& c);
    

    […]

    -4- Requires: T shall be MoveInsertable into *this and CopyInsertable into *this.

  2. Edit 23.3.6.3 [vector.capacity]/16+17 as indicated:

    void resize(size_type sz, const T& c);
    

    […]

    -16- Requires: T shall be MoveInsertable into *this and CopyInsertable into *this.

    -17- Remarks: If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.


2324. Insert iterator constructors should use addressof()

Section: 24.5.2.2.1 [back.insert.iter.cons], 24.5.2.4.1 [front.insert.iter.cons], 24.5.2.6.1 [insert.iter.cons] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all issues with New status.

Discussion:

24.5.2.2.1 [back.insert.iter.cons]/1, 24.5.2.4.1 [front.insert.iter.cons]/1, and 24.5.2.6.1 [insert.iter.cons]/1 say "Initializes container with &x", which doesn't defend against containers overloading operator&(). Containers are now required to have such defenses for their elements, so we may as well be consistent here.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 24.5.2.2.1 [back.insert.iter.cons]/1 as indicated:

    explicit back_insert_iterator(Container& x);
    

    -1- Effects: Initializes container with &xstd::addressof(x).

  2. Edit 24.5.2.4.1 [front.insert.iter.cons]/1 as indicated:

    explicit front_insert_iterator(Container& x);
    

    -1- Effects: Initializes container with &xstd::addressof(x).

  3. Edit 24.5.2.6.1 [insert.iter.cons]/1 as indicated:

    insert_iterator(Container& x, typename Container::iterator i);
    

    -1- Effects: Initializes container with &xstd::addressof(x) and iter with i.


2325. minmax_element()'s behavior differing from max_element()'s should be noted

Section: 25.4.7 [alg.min.max] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [alg.min.max].

View all other issues in [alg.min.max].

View all issues with New status.

Discussion:

25.4.7 [alg.min.max]/23 says that max_element() finds the first biggest element, while /25 says that minmax_element() finds the last biggest element. This significant difference is unusual — it means that minmax_element(args) is not equivalent to make_pair(min_element(args), max_element(args)), whereas the other major "two for one" algorithm equal_range(args) is equivalent to make_pair(lower_bound(args), upper_bound(args)). minmax_element()'s behavior is intentional — it is a fundamental consequence of the 3N/2 algorithm — but the Standardese does not draw attention to this in any way. This wording came from LWG 715's resolution (which changed the semantics but didn't mention it), citing CLRS for the algorithm — but CLRS doesn't mention the behavior for equivalent elements! The wording here deeply confused me (as an STL maintainer fixing an incorrect implementation) until I walked through the algorithm by hand and figured out the fundamental reason. It would be really nice for the Standard to provide a hint that something magical is happening here.

Proposed resolution:

This wording is relative to N3691.

  1. Add a footnote to 25.4.7 [alg.min.max]/25 as indicated:

    template<class ForwardIterator>
      pair<ForwardIterator, ForwardIterator>
        minmax_element(ForwardIterator first, ForwardIterator last);
    template<class ForwardIterator, class Compare>
      pair<ForwardIterator, ForwardIterator>
        minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
    

    -25- Returns: make_pair(first, first) if [first,last) is empty, otherwise make_pair(m, M), where m is the first iterator in [first,last) such that no iterator in the range refers to a smaller element, and where M is the last iterator [Footnote: This behavior intentionally differs from max_element().] in [first,last) such that no iterator in the range refers to a larger element.


2326. uniform_int_distribution<unsigned char> should be permitted

Section: 26.5.1.1 [rand.req.genl] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all issues with New status.

Discussion:

26.5.1.1 [rand.req.genl]/1 says: "Throughout this subclause 26.5, the effect of instantiating a template [...] that has a template type parameter named IntType is undefined unless the corresponding template argument is cv-unqualified and is one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long." 26.5.8.2.1 [rand.dist.uni.int] specifies template<class IntType = int> class uniform_int_distribution, so this forbids uniform_int_distribution<char/signed char/unsigned char>.

I am not aware of anything in <random> that works with 16-bit integers but fails with 8-bit integers, so I suspect that IntType and UIntType could simply be extended to permit the char family. Alternatively, this change could be limited to uniform_int_distribution alone, where it is definitely safe. A <random> expert should decide which change is best.

Proposed resolution:


2327. Non-power-of-two URNGs should be forbidden

Section: 26.5.1.3 [rand.req.urng] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [rand.req.urng].

View all other issues in [rand.req.urng].

View all issues with New status.

Discussion:

26.5.1.3 [rand.req.urng] allows URNGs with non-power-of-two (NPOT) ranges, like [0, 1729]. This is unnecessarily permissive (I cannot imagine a realistic source of randomness that would generate such a range) and has real costs for implementers, as uniform_int_distribution must be prepared to accept such URNGs. The most efficient way to accumulate randomness is to concatenate random bits, so NPOT randomness is not just useless, it is actively harmful (to avoid bias, if a URNG generates a random number outside of a power-of-two range, the number must be discarded).

Forbidding NPOT URNGs wouldn't affect users, and would simplify Standard Library implementations. It would be nice to require min() to be 0, but this is not necessary; it is simple for implementations to say g() - G::min() and this will optimize away if min() is 0. (It is vaguely plausible for a URNG to have a nonzero minimum; I can imagine something that simply masks off low-order bits without shifting the rest downwards.) What is important is for the entire range to have a power-of-two width; [1729, 1984] is acceptable as its size is 256.

[2013-10-12: Howard presents a counterexample]

Consider:

#include <random>
#include <string>
#include <iostream>

template <class Int>
bool is_power_2m1(Int i)
{
  return (i & (i + 1)) == 0;
}

template <class URNG>
void test(const std::string& urng)
{
  using namespace std;
  typename URNG::result_type rng = URNG::max() - URNG::min();
  if (!is_power_2m1(rng))
  {
    cout << hex;
    cout << urng << " : min = " << URNG::min() << ", max = " << URNG::max()
         << ", max-min = " << rng << '\n';
  }
};

int main()
{
    using namespace std;
    test<minstd_rand0>("minstd_rand0");
    test<minstd_rand>("minstd_rand");
    test<mt19937>("mt19937");
    test<mt19937_64>("mt19937_64");
    test<ranlux24_base>("ranlux24_base");
    test<ranlux48_base>("ranlux48_base");
    test<ranlux24>("ranlux24");
    test<ranlux48>("ranlux48");
    test<knuth_b>("knuth_b");
}

Which for me outputs:

minstd_rand0 : min = 1, max = 7ffffffe, max-min = 7ffffffd
minstd_rand : min = 1, max = 7ffffffe, max-min = 7ffffffd
knuth_b : min = 1, max = 7ffffffe, max-min = 7ffffffd

We do not want to outlaw these three URNG's, and the proposed wording would do that.

Proposed resolution:

This wording is relative to N3691.

  1. Add a new paragraph at the end of 26.5.1.3 [rand.req.urng] as indicated:

    -3- The following relation shall hold: G::min() < G::max().

    -?- G::max() - G::min() shall be 2n - 1 for some n > 0.


2328. Rvalue stream extraction should use perfect forwarding

Section: 27.7.2.6 [istream.rvalue] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all issues with New status.

Discussion:

27.7.2.6 [istream.rvalue] declares operator>>(basic_istream<charT, traits>&& is, T& x). However, 27.7.2.2.3 [istream::extractors]/7 declares operator>>(basic_istream<charT,traits>& in, charT* s), plus additional overloads for unsigned char* and signed char*. This means that "return_rvalue_istream() >> &arr[0]" won't compile, because T& won't bind to the rvalue &arr[0].

Proposed resolution:

This wording is relative to N3691.

  1. Edit 27.7.1 [iostream.format.overview], header <istream> synopsis, as indicated:

    namespace std {
      […]
      template <class charT, class traits, class T>
        basic_istream<charT, traits>&
        operator>>(basic_istream<charT, traits>&& is, T&& x);
    }
    
  2. Edit 27.7.2.6 [istream.rvalue] as indicated:

    template <class charT, class traits, class T>
      basic_istream<charT, traits>&
      operator>>(basic_istream<charT, traits>&& is, T&& x);
    

    -1- Effects: is >>x std::forward<T>(x)

    -2- Returns: is


2329. regex_match()/regex_search() with match_results should forbid temporary strings

Section: 28.4 [re.syn] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all other issues in [re.syn].

View all issues with New status.

Discussion:

Consider the following code:

const regex r(R"(meow(\d+)\.txt)");
smatch m;
if (regex_match(dir_iter->path().filename().string(), m, r)) {
  DoSomethingWith(m[1]);
}

This occasionally crashes. The problem is that dir_iter->path().filename().string() returns a temporary string, so the match_results contains invalidated iterators into a destroyed temporary string.

It's fine for regex_match/regex_search(str, reg) to accept temporary strings, because they just return bool. However, the overloads taking match_results should forbid temporary strings.

Proposed resolution:

This wording is relative to N3691.

  1. Edit 28.4 [re.syn], header <regex> synopsis, as indicated:

    #include <initializer_list>
    
    namespace std {
    
      […]
      
      // 28.11.2, function template regex_match:
      […]
      template <class ST, class SA, class Allocator, class charT, class traits> 
      bool regex_match(const basic_string<charT, ST, SA>&&, 
                       match_results<
                         typename basic_string<charT, ST, SA>::const_iterator, 
                         Allocator>&, 
                       const basic_regex<charT, traits>&, 
                       regex_constants::match_flag_type = 
                         regex_constants::match_default) = delete;
    
      // 28.11.3, function template regex_search:
      […]
      template <class ST, class SA, class Allocator, class charT, class traits> 
      bool regex_search(const basic_string<charT, ST, SA>&&, 
                        match_results<
                          typename basic_string<charT, ST, SA>::const_iterator, 
                          Allocator>&, 
                        const basic_regex<charT, traits>&, 
                        regex_constants::match_flag_type = 
                          regex_constants::match_default) = delete;
      […]
    }
    

2330. regex("meow", regex::icase) is technically forbidden but should be permitted

Section: 28.5.1 [re.synopt] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [re.synopt].

View all other issues in [re.synopt].

View all issues with New status.

Discussion:

28.5.1 [re.synopt]/1 says "A valid value of type syntax_option_type shall have exactly one of the elements ECMAScript, basic, extended, awk, grep, egrep, set."

This "exactly one" wording technically forbids passing icase by itself! Users should not be required to pass regex::ECMAScript | regex::icase. (Note that the cost of an additional check for no grammar being explicitly requested is completely irrelevant, as regex construction is so much more expensive.)

Proposed resolution:

This wording is relative to N3691.

  1. Edit 28.5.1 [re.synopt] as indicated:

    -1- The type syntax_option_type is an implementation-defined bitmask type (17.5.2.1.3). Setting its elements has the effects listed in table 138. A valid value of type syntax_option_type shall have exactlyat most one of the grammar elements ECMAScript, basic, extended, awk, grep, egrep, set. If no grammar element is set, the default grammar is ECMAScript.


2331. regex_constants::collate's effects are inaccurately summarized

Section: 28.5.1 [re.synopt] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View other active issues in [re.synopt].

View all other issues in [re.synopt].

View all issues with New status.

Discussion:

The table in 28.5.1 [re.synopt]/1 says that regex_constants::collate "Specifies that character ranges of the form "[a-b]" shall be locale sensitive.", but 28.13 [re.grammar]/14 says that it affects individual character comparisons too.

Proposed resolution:

This wording is relative to N3691.

  1. In 28.5.1 [re.synopt]/1, Table 138 — "syntax_option_type effects", change as indicated:

    Table 138 — syntax_option_type effects
    Element Effect(s) if set
    collate Specifies that character ranges of the form "[a-b]"comparisons and character range comparisons shall be locale sensitive.

2332. regex_iterator/regex_token_iterator should forbid temporary regexes

Section: 28.12 [re.iter] Status: New Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2013-10-15

View all issues with New status.

Discussion:

Users can write "for(sregex_iterator i(s.begin(), s.end(), regex("meow")), end; i != end; ++i)", binding a temporary regex to const regex& and storing a pointer to it. This will compile silently, triggering undefined behavior at runtime. We now have the technology to prevent this from compiling, like how reference_wrapper refuses to bind to temporaries.

Proposed resolution:

This wording is relative to N3691.

  1. Change 28.12.1 [re.regiter]/1, class template regex_iterator synopsis, as indicated:

    regex_iterator();
    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
      const regex_type& re,
      regex_constants::match_flag_type m =
        regex_constants::match_default);
    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
      const regex_type&& re,
      regex_constants::match_flag_type m =
        regex_constants::match_default) = delete;
    
  2. Change 28.12.2 [re.tokiter]/6, class template regex_token_iterator synopsis, as indicated:

    regex_token_iterator();
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         int submatch = 0,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         const std::vector<int>& submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         initializer_list<int> submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    template <std::size_t N>
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         const int (&submatches)[N],
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         int submatch = 0,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         const std::vector<int>& submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         initializer_list<int> submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    template <std::size_t N>
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         const int (&submatches)[N],
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    

2333. Hashing disengaged optional<T> objects

Section: X [optional.hash] Status: Deferred Submitter: Jonathan Wakely Opened: 2013-10-03 Last modified: 2013-10-15

View all issues with Deferred status.

Discussion:

The spec for hash<optional<T>> doesn't say anything about disengaged objects, so 1.3.24 [defns.undefined] would imply it's undefined behaviour, but that's very unhelpful to users.

If hashing disengaged optional objects is undefined there should be a Requires, otherwise there should be some statement saying it's OK.

It would be possible to specify the value, e.g. saying it returns the same value as something like std::hash<void*>()(nullptr), but leaving it unspecified would permit users to specialize hash<optional<UserDefinedType>> so that the hash value for a disengaged object is distinct from any value returned by hash<UserDefinedType>.

Proposed resolution:

This wording is relative to N3691.

  1. Add to X [optional.hash]/3

    template <class T> struct hash<optional<T>>;
    

    […]

    -3- For an object o of type optional<T>, if bool(o) == true, hash<optional<T>>()(o) shall evaluate to the same value as hash<T>()(*o) otherwise it evaluates to an unspecified value.


2334. atomic's default constructor requires "uninitialized" state even for types with non-trivial default-constructor

Section: 29.6.5 [atomics.types.operations.req] Status: New Submitter: Daniel Krügler Opened: 2013-10-03 Last modified: 2013-10-15

View all other issues in [atomics.types.operations.req].

View all issues with New status.

Discussion:

According to 29.6.5 [atomics.types.operations.req] p4,

A ::A () noexcept = default;

Effects: leaves the atomic object in an uninitialized state. [Note: These semantics ensure compatibility with C. — end note]

This implementation requirement is OK for POD types, like int, but 29.5 [atomics.types.generic] p1 intentionally allows template arguments of atomic with a non-trivial default constructor ("The type of the template argument T shall be trivially copyable (3.9)"), so this wording can be read in a way that makes the behaviour of the following code undefined:

#include <atomic>
#include <iostream>

struct S {
  S() noexcept : v(42) {}
  int v;
};

int main() {
  std::atomic<S> as; // Default-initialization
  std::cout << as.load().v << std::endl; // ?
}

For a user-defined emulation of atomic the expected outcome would be defined and the program would output "42", but existing implementations differ and the result value is a "random number" for at least one implementation. This seems very surprising to me.

To realize that seemingly existing requirement, an implementation is either required to violate normal language rules internally or to perform specific bit-randomization-techniques after the normal default-initialization that called the default constructor of S.

According to my understanding, the non-normative note in 29.6.5 [atomics.types.operations.req] p4 is intended to refer to types that are valid C-types, but the example type S is not such a type.

To make the mental model of atomic's default constructor more intuitive for user-code, I suggest to clarify the wording to have the effects of default-initialization instead. The current state seems more like an unintended effect of imprecise language used here and has some similarities to wording that was incorrectly used to specify atomic_flag initialization as described by LWG 2159.

Proposed resolution:

This wording is relative to N3691.

  1. Modify 29.6.5 [atomics.types.operations.req] p4 as indicated: [Editorial note: There is no exposition-only member in atomic, which makes it a bit hard to specify what actually is initialized, but the usage of the term "value" seems consistent with similar wording used to specify the effects of the atomic load functions]

    A ::A () noexcept = default;
    

    -4- Effects: leaves the atomic object in an uninitialized stateThe value of the atomic object is default-initialized (8.5 [dcl.init]). [Note: These semantics ensure compatibility with C. — end note]


2335. array<array<int, 3>, 4> should be layout-compatible with int[4][3]

Section: 23.3.2 [array] Status: New Submitter: Jeffrey Yasskin Opened: 2013-10-04 Last modified: 2013-10-15

View all other issues in [array].

View all issues with New status.

Discussion:

In order to replace some uses of C arrays with std::array, we need it to be possible to cast from a std::array<> to an equivalent C array. Core wording doesn't appear to be in quite the right state to allow casting, but if we specify that appropriate types are layout-compatible, we can at least write:

union {
  array<array<array<int, 2>, 3>, 4> arr;
  int carr[4][3][2];
};

to view memory as the other type: C++14 CD [class.mem]p18.

I believe it's sufficient to add "array<T, N> shall be layout-compatible (3.9 [basic.types]) with T[N]." to 23.3.2.1 [array.overview], but we might also need some extension to 9.2 [class.mem] to address the possibility of layout-compatibility between struct and array types.

I checked that libc++ on MacOS already implements this, although it would be good for someone else to double-check; I haven't checked any other standard libraries.

Proposed resolution:


2336. is_trivially_constructible/is_trivially_assignable traits are always false

Section: 20.10.4.3 [meta.unary.prop] Status: New Submitter: Daniel Krügler Opened: 2013-10-01 Last modified: 2013-11-28

View other active issues in [meta.unary.prop].

View all other issues in [meta.unary.prop].

View all issues with New status.

Discussion:

In 20.10.4.3 [meta.unary.prop] we have traits to allow testing for triviality of specific operations, such as is_trivially_constructible and is_trivially_assignable (and their derived forms), which are specified in terms of the following initialization and assignment, respectively:

T t(create<Args>()...);

declval<T>() = declval<U>()

The wording that describes the way how triviality is deduced, is in both cases of the same form:

[… ] and the variable definition/assignment, as defined by is_constructible/is_assignable, is known to call no operation that is not trivial (3.9, 12).

The problematic part of this wording is that both definitions are specified in terms of an "object construction" function create or declval, respectively, (The former being a conceptual function, the latter being a library function), but for none of these functions we can assume that they could be considered as trivial — only special member functions can have this property and none of these is one. This problem became obvious, when the similar issue LWG 2298 in regard to is_nothrow_constructible was opened.

A possible approach to solve this specification problem is to make a blanket statement for sub-clause 20.10.4.3 [meta.unary.prop] that these helper functions are considered trivial for the purpose of defining these traits.

Using this kind of wording technique can also be used to get rid of the additional helper function template create, which is currently needed for the is_convertible and the is_constructible traits, because both traits are specified in terms of contexts where technically the corresponding "object construction" function would be considered as odr-used. This is problematic, because these traits are defined in terms of well-formed code and odr-using declval would make the program ill-formed (see 20.2.5 [declval]). So extending above blanket statement to consider std::declval<T>() as not odr-used in the context of the corresponding trait definition would allow for replacing create by declval.

Proposed resolution:

This wording is relative to N3691.

  1. Add a new paragraph after 20.10.4.3 [meta.unary.prop] p3 as indicated: [Editorial note: The first change in 20.10.4.3 [meta.unary.prop] p3 is recommended, because technically a Clause is always a "main chapter" — such as Clause 20 — but every child of a Clause or sub-clause is a sub-clause]

    […]

    -3- For all of the class templates X declared in this Clausesub-clause, instantiating that template with a template-argument that is a class template specialization may result in the implicit instantiation of the template argument if and only if the semantics of X require that the argument must be a complete type.

    -?- For the purpose of defining the templates in this sub-clause, a function call expression declval<T>() for any type T is considered to be a trivial (3.9 [basic.types], 12 [special]) function call that is not an odr-use (3.2 [basic.def.odr]) of declval in the context of the corresponding definition notwithstanding the restrictions of 20.2.5 [declval].

    […]

  2. Modify 20.10.4.3 [meta.unary.prop] p6 as indicated:

    -6- Given the following function prototype:

    template <class T>
      typename add_rvalue_reference<T>::type create();
    

    tThe predicate condition for a template specialization is_constructible<T, Args...> shall be satisfied if and only if the following variable definition would be well-formed for some invented variable t:

    T t(createdeclval<Args>()...);
    

    […]

  3. Add a new paragraph after 20.10.6 [meta.rel] p2 as indicated: [Editorial note: Technically we don't need the guarantee of "a trivial function call" for the type relationship predicates at the very moment, but it seems more robust and consistent to have the exact same guarantee here as well]

    […]

    -2- […]

    -?- For the purpose of defining the templates in this sub-clause, a function call expression declval<T>() for any type T is considered to be a trivial (3.9 [basic.types], 12 [special]) function call that is not an odr-use (3.2 [basic.def.odr]) of declval in the context of the corresponding definition notwithstanding the restrictions of 20.2.5 [declval].

    […]

  4. Modify 20.10.6 [meta.rel] p4 as indicated:

    -4- Given the following function prototype:

    template <class T>
      typename add_rvalue_reference<T>::type create();
    

    tThe predicate condition for a template specialization is_convertible<From, To> shall be satisfied if and only if the return expression in the following code would be well-formed, including any implicit conversions to the return type of the function:

    To test() {
      return createdeclval<From>();
    }
    

    […]


2337. shared_ptr operator*() should not be noexcept

Section: 20.8.2.2.5 [util.smartptr.shared.obs] Status: New Submitter: Stephan T. Lavavej Opened: 2013-10-05 Last modified: 2013-10-15

View all othe