Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #262

Re: Defect Report: Wordings on basic_string::data() disallow small-string optimization

From Kazutoshi Satoda <k_satoda@f2.dion.ne.jp>
Newsgroups comp.std.c++
Subject Re: Defect Report: Wordings on basic_string::data() disallow small-string optimization
Date 2011-08-28 08:42 -0700
Organization unknown
Message-ID <4E591721.2020208@f2.dion.ne.jp> (permalink)

Show all headers | View raw


> You cannot make normative conclusions from this code, because it invokes
> undefined behaviour. This is so, because the expression
>
> x = std::move(str)
>
> calls a function that (potentially) invalidates the pointer returned
> fromstr.data(), based on 21.4.1 [string.require] p6:
>
> "References, pointers, and iterators referring to the elements of a
> basic_string sequence may be invalidated by the following uses of that
> basic_string object:
> � as an argument to any standard library function taking a reference to
> non-const basic_string as an argument.(footnote)
> � Calling non-const member functions, except operator[], at, front,
> back, begin, rbegin, end, and rend."

In the previous reply, I took "standard library function taking a
reference to ..." as std::move() in the above expression.

But if you are referring operator=(basic_string&&) itself as the
trigger of invalidation, it seems impossible to show the problem with a
valid C++ code example, because comparison of pointers is the only way
in C++ to examine the effect on data().
>
> data(): points at the array whose first element was pointed at by str.data()

Returning to the original DR;
It is not possible to confirm the above effect of data() if small-string
optimization is implemented, because data() may point an small array
which is distinct for each basic_string instance to decrease the number
of allocation.

--
k_satoda


[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextNext in thread | Find similar


Thread

Re: Defect Report: Wordings on basic_string::data() disallow small-string optimization Kazutoshi Satoda <k_satoda@f2.dion.ne.jp> - 2011-08-28 08:42 -0700
  Re: Defect Report: Wordings on basic_string::data() disallow small-string optimization Daniel Krügler<daniel.kruegler@googlemail.com> - 2011-08-28 11:07 -0700

csiph-web