Monday, March 29, 2021

Digest for comp.lang.c++@googlegroups.com - 9 updates in 3 topics

Juha Nieminen <nospam@thanks.invalid>: Mar 29 06:26AM


> I could assume that no one would be so stupid to do sth. like this:
> Obj const &o = Obj();
> So if I make this assumption, what's the solution ?
 
The lifetime of the temporary will be extended to the lifetime of the
reference in that case, so it's not completely stupid.
Juha Nieminen <nospam@thanks.invalid>: Mar 29 06:27AM

> Is there a way to enforce that an object
> can be only instantiated as a temporary ?
 
I'm thinking what happens if all the member functions are
rvalue-qualified, but I haven't tested if that will introduce
that limitation. Maybe not.
Bonita Montero <Bonita.Montero@gmail.com>: Mar 29 09:00AM +0200

>> So if I make this assumption, what's the solution ?
 
> The lifetime of the temporary will be extended to the lifetime of the
> reference in that case, so it's not completely stupid.
 
You're right, and look at this:
 
#include <iostream>
 
using namespace std;
 
struct S
{
S()
{
cout << "S::S()" << endl;
}
~S()
{
cout << "~S::S()" << endl;
}
};
 
int main( int argc, char **argv )
{
S const &s = argc < 0 ? S() : S();
cout << "after destruction?" << endl;
}
 
Of course argc can never be < 0, but the compiler doesn't know that.
So look at the output:
 
S::S()
~S::S()
after destruction!
~S::S()
 
So the code destructs only one object within the statement !
Richard Damon <Richard@Damon-Family.org>: Mar 29 07:45AM -0400

On 3/29/21 3:00 AM, Bonita Montero wrote:
> after destruction!
> ~S::S()
 
> So the code destructs only one object within the statement !
 
You didn't define a copy constructor, so there may have been a second S
created as a copy of the first, to bind to the reference.
Bonita Montero <Bonita.Montero@gmail.com>: Mar 29 06:56PM +0200


>> So the code destructs only one object within the statement !
 
> You didn't define a copy constructor, so there may have been a second S
> created as a copy of the first, to bind to the reference.
 
You have too much phantasy. That's for sure not required by the
standard, nor it would be realistic that any compiler would do
it that way.
Manfred <noname@add.invalid>: Mar 29 07:59PM +0200

On 3/29/2021 6:56 PM, Bonita Montero wrote:
 
> You have too much phantasy. That's for sure not required by the
> standard, nor it would be realistic that any compiler would do
> it that way.
 
It's no fantasy, that is what is happening in reality - if you use msvc
(gcc makes no copy) - you would have seen it yourself if you had a copy
(and a move) ctor defined.
[BTW ~S::S() should be S::~S()]
Paavo Helde <myfirstname@osa.pri.ee>: Mar 29 10:26PM +0300

29.03.2021 19:56 Bonita Montero kirjutas:
 
> You have too much phantasy. That's for sure not required by the
> standard, nor it would be realistic that any compiler would do
> it that way.
 
If you think a copy ctor does not get used in your little experiment,
then how do you explain the output you saw? Or do you suggest the
compiler is buggy and destructs the same object twice? (Hint: it does not.)
legalize+jeeves@mail.xmission.com (Richard): Mar 29 05:37PM

[Please do not mail me a copy of your followup]
 
Lynn McGuire <lynnmcguire5@gmail.com> spake the secret code
 
>"What Will Die Out Sooner C++ or C++ Programmers?" by Oleksandr Kaleniuk
 
IMO, this is just a flamey attention-seeking blog post, not a well
reasoned argument.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 29 08:17AM +0200

On 28.03.2021 15:56, David Brown wrote:
 
> Google groups is broken - amongst its many flaws (and some advantages),
> it currently will not let you post a new thread in a group with symbols
> in the name, like comp.lang.c++.
 
Wow.
 
Since I remember a very long string of similarly explanation-defying
problems over a period of 20 years, plus the infamous "wall of Google"
where it's impossible to get hold of a human there, I conclude that
Google sabotages Usenet.
 
The silly bastards (what with discrimination in the workplace there,
firing AI ethics researchers, China, so on) probably see Usenet as a
competitor to their stream of solutions that few have ever wanted.
 
 
> common free choice is Thunderbird for the client,
> news.eternal-september.org as the server. (There are many other clients
> and servers according to preference.)
 
What about Quora and other newfangled discussion arenas?
 
 
- Alf
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: