[LLVMbugs] [Bug 23852] vector of const - push_back fail

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jun 15 21:01:14 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23852

Marshall Clow (home) <mclow.lists at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID
           Assignee|unassignedclangbugs at nondot. |mclow.lists at gmail.com
                   |org                         |

--- Comment #1 from Marshall Clow (home) <mclow.lists at gmail.com> ---
The standard says the requirement for push_back is that the value type (T) of a
vector needs to be "T shall be CopyInsertable into X." (where X is the
container) [Table 100]

What does that mean? [23.2.1/15] says:

Given a container type X having an allocator_type identical to A and a
value_type identical to T and given an lvalue m of type A, a pointer p of type
T*, an expression v of type (possibly const) T ...

(skip ahead to p15.4)

T is CopyInsertable into X means that, in addition to T being MoveInsertable
into X, the following expression is well-formed:
     allocator_traits<A>::construct(m, p, v)

and its evaluation causes the following postcondition to hold: The value of v
is unchanged and is equivalent to *p.

So, it needs to be able to this:
    std::allocator<const int> a;
    const int *p;
    int v = 17;
    std::allocator_traits<std::allocator<const int>>::construct(m, p, v);

but p is a pointer to const int - and so the allocator cannot construct a new
int there.

Hence, the compile failure.


In general, containers of const types is a bad idea.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150616/80b64f64/attachment.html>


More information about the llvm-bugs mailing list