Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <87y4xaikuu.fsf@Niukka.kon.iki.fi> (permalink) |
|---|---|
| Newsgroups | comp.std.c++ |
| From | Kalle Olavi Niemitalo <kon@iki.fi> |
| Subject | Re: Is removing necessity of std::move for local variables used for the last time a good proposal? |
| Organization | unknown |
| References | <874c0712-4aed-4a8f-991e-b064daa5000f@googlegroups.com> <263da605-5281-469e-86b4-6209739c6133@googlegroups.com> |
| Date | 2014-06-07 01:25 -0600 |
[Dear moderator, please replace my previous message on this topic.]
SG <s.gesemann@googlemail.com> writes:
> So far, as you probably know, a compiler is not required nor allowed
> to do that. I think there is some value in further analyzing the
> impact of such a rule. We would not want this rule to break something.
> I've trouble coming up with examples that would break, but it does
> not mean that there are none. It would be nice to have a somewhat
> formal proof under reasonable assumptions that nothing could go wrong.
#include <memory>
#include <mutex>
std::mutex m;
int i;
void f1(std::shared_ptr<std::lock_guard<std::mutex> > p);
void f2()
{
auto p = std::make_shared<std::lock_guard<std::mutex> >(m);
++i;
f1(p);
++i;
}
If f1(p) automatically changed to f1(std::move(p)), then the
mutex would be unlocked already before the second ++i; statement.
The following example seems more realistic:
#include <cstdio>
#include <string>
void f1(std::string s) {}
int main()
{
std::string s("hello");
const char *p = s.c_str();
f1(s);
std::puts(p);
}
If f1(s) automatically changed to f1(std::move(s)), then the
pointer p would no longer be valid after f1 returns.
--
[ 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 | Next — Previous in thread | Next in thread | Find similar
Is removing necessity of std::move for local variables used for the last time a good proposal? Piotr Nycz <piotrwn1@googlemail.com> - 2014-05-30 15:32 -0600
Re: Is removing necessity of std::move for local variables used for the last time a good proposal? SG <s.gesemann@googlemail.com> - 2014-06-05 12:31 -0600
Re: Is removing necessity of std::move for local variables used for the last time a good proposal? Kalle Olavi Niemitalo <kon@iki.fi> - 2014-06-07 01:25 -0600
Re: Is removing necessity of std::move for local variables used for the last time a good proposal? Piotr Nycz <piotrwn1@googlemail.com> - 2014-06-07 02:33 -0600
Re: Is removing necessity of std::move for local variables used for the last time a good proposal? Daniel Krügler <daniel.kruegler@googlemail.com> - 2014-06-08 01:32 -0600
Re: Is removing necessity of std::move for local variables used for the last time a good proposal? Piotr Nycz <piotrwn1@googlemail.com> - 2014-06-17 07:25 -0600
csiph-web