[libcxx-commits] [PATCH] D110497: [libc++][format][3/6] Adds a __container_buffer.

Victor Zverovich via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 31 09:25:20 PDT 2021


vitaut added inline comments.


================
Comment at: libcxx/include/__format/buffer.h:94
+///
+/// \note a \a _Container needs to opt-in to the concept by adding a typedef
+/// \ref __enable_format_insertable with the same type as \a _Container.
----------------
Quuxplusone wrote:
> vitaut wrote:
> > opt-in to -> "opt in to" or "opt into"
> >>! In D110497#3098970, @vitaut wrote:
> >> Since there's no guarantee every container's insert behaves properly
> > 
> > What does behaving properly mean? Could you give an example of a container's insert that doesn't behave properly?
> 
> User-defined containers can make their `insert` do arbitrary things, e.g.
> ```
> struct Evil : std::string {
>     void insert(std::string::iterator, char *, char *) { /*no-op*/ }
> };
> Evil e;
> auto evil_it = std::back_inserter(e);  // uses e.push_back, which is fine
> ```
> (Serendipitously, Charlie Barto, of the MSVC STL, also mentioned the need to guard against this possibility in his CppCon talk "Why does std::format do that?" on Thursday. https://cppcon.digital-medium.co.uk/thursday-recordings/ )
Makes sense, thanks for clarifying.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110497/new/

https://reviews.llvm.org/D110497



More information about the libcxx-commits mailing list