#include <new>
class T
{
};
int main()
{
T t = t;
T u(u);
T v;
new (&v) T(v);
}
Kiuhnm 30 2111
Kiuhnm wrote: #include <new>
class T { };
int main() { T t = t; T u(u); T v; new (&v) T(v); }
Kiuhnm
Have you tried compiling this?
Does you compiler give you errors?
Why do you think that is?
What do you expect each line to do?
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Ben Pope ha scritto: Have you tried compiling this?
Yes, but it is irrelevant. How can I be sure that my compiler is
completely standard-compliant?
What do you expect each line to do?
It is irrelevant.
All I would like to know is whether the code, according to the standard,
produces a defined behavior or not.
Kiuhnm
Kiuhnm wrote: Ben Pope ha scritto: Have you tried compiling this?
Yes, but it is irrelevant. How can I be sure that my compiler is completely standard-compliant?
You can't. What do you expect each line to do?
It is irrelevant. All I would like to know is whether the code, according to the standard, produces a defined behavior or not.
Not.
In article <44************ ***********@rea der1.news.tin.i t>,
Kiuhnm <"kiuhnm03["@]yahoo.it> wrote: Ben Pope ha scritto: Have you tried compiling this?
Yes, but it is irrelevant. How can I be sure that my compiler is completely standard-compliant?
What do you expect each line to do?
It is irrelevant. All I would like to know is whether the code, according to the standard, produces a defined behavior or not.
T t = t;
T u(u);
The above two lines will compile but the behavior is undefined.
T v;
new (&v) T(v);
The above two lines produce defined behavior.
Please, why do you ask?
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Rolf Magnus ha scritto: Not.
Why?
I read 3.3.1 and 3.8 in the c++ iso, but that did not clarify my doubts.
Kiuhnm
Daniel T. ha scritto: T t = t; T u(u);
The above two lines will compile but the behavior is undefined.
And what about
int x = x;
?
Please, why do you ask?
I am just curious.
Kiuhnm
Kiuhnm" <"kiuhnm03[ wrote: Daniel T. ha scritto: T t = t; T u(u);
The above two lines will compile but the behavior is undefined.
And what about int x = x; ?
What's the difference from
T t = t;
do you see here?
V
--
Please remove capital As from my address when replying by mail
Kiuhnm wrote: #include <new>
class T { };
int main() { T t = t; T u(u); T v; new (&v) T(v); }
What is your particular question anyway? What do you suspect to be
illegal and why? The obvious violation is double construction of an
object which is illegal. However, you put other stuff into the
article, too, which might indicate that you are actually looking for
other sources of "illegal code".
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Dietmar Kuehl wrote: Kiuhnm wrote: #include <new>
class T { };
int main() { T t = t; T u(u); T v; new (&v) T(v); } What is your particular question anyway?
He is asking because we have been discussing that in our national C++
newsgroup but did not come to a definitive conclusion.
There are more variations on the same theme and they may or may not
change the validity of those constructs.
What do you suspect to be illegal and why?
It depends who you ask to. If we had any consensus we would not even ask.
For as much as we can say the placement new construct is perfectly defined.
That is:
void foo()
{
class T {} v;
new (&v) T(v);
}
is perfectly legal.
The obvious violation is double construction of an object which is illegal.
Not. The standard does not say you cannot construct twice. And does not
guarantee that the number of constructions matches the number of
destructions. If you reuse the memory of a live object, that object
lifetime ends without the construction being called and it is explicitly
legal to do so. See 3.8#4
However, you put other stuff into the article, too, which might indicate that you are actually looking for other sources of "illegal code".
In fact 3.8 is no help in the other cases.
We know that
struct T {
void *p;
T(){}
T(T*pp){ p=pp; if (pp==this) cout << "wow!\n"; }
};
void foo()
{
T t=&t;
T u(&u);
}
is perfectly defined (see 3.3.1#1 and 3.8#5)
But the wording in 3.8, specifically the first item of the list in
3.8#5, together with 3.8#1 seem to imply that
struct T {
int i;
T(){}
T(const T&r){i=r.i;}
};
void foo()
{
T t=t;
T u(u);
}
is undefined behavior (cannot access r.i until the lifetime has begun,
and that happens at the end of the constructor).
And this is apparently incongruous with the fact that
void foo()
{
int i=i;
int j(j);
}
is perfectly valid as in 3.3.1#1 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Adrian B. |
last post by:
Does anyone know of a framework or library that will enable me to use
publish/subscribe comms? I want to create a server (using Python)
running on a Unix box that will accept client connections (from GUIs
built with wxPython) and publish realtime data updates to them. Any
advice on where to start?
Thanks.
A.B.
|
by: George Sakkis |
last post by:
Is there a general way of injecting code into a function, typically
before and/or after the existing code ? I know that for most purposes,
an OO solution, such as the template pattern, is a cleaner way to get
the same effect, but it's not always applicable (e.g. if you have no
control over the design and you are given a function to start...
|
by: Chris Johnson |
last post by:
Greetings all:
I come across an interesting question (to me anyway) and I do not
know the answer. Code/Questions follow:
#include <iostream>
#if 0
// uncommenting *should* make call ambigous because of
// odering deduction of the function signature,
|
by: vb |
last post by:
hi all,
I have to compare an address of structure with an absolute address(this
address signifies the start of a memory component).
Now my question is the follwong code leagal:-
#include <stdio.h>
int main()
{
struct t{
|
by: Vortex Soft |
last post by:
http://www.junglecreatures.com/
Try it and tell me what's happenning in the Microsoft Corporation.
Notes:
VB, C# are CLS compliant
| |
by: jaso |
last post by:
Can you give any comments on this code?
I used one goto, is it bad?
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#define NOT_NULL 1
|
by: Jon Skeet [C# MVP] |
last post by:
I'm sure the net will be buzzing with this news fairly soon, but just
in case anyone hasn't seen it yet:
Microsoft are going to make the source code for the .NET framework
(parts of it, including the BCL, ASP.NET and LINQ) available both for
viewing and debugging into.
I won't go into all the details here, as they're covered on Scott...
|
by: sara |
last post by:
Hi -
I have a report that is 14 columnar sub-reports (Line up: Position-
holders in each of our 14 locations - Manager, Assistant Manager,
Receiving, Office, etc).
I output directly to PDF (using ConvertReportToPDF from this site -
Stephan Lebans)
The formatting - Outlines on some fields - do not appear on subreports
|
by: eduzea |
last post by:
I have some code that compiles with gcc but fails with MS VC 8. I
would like to know which one is following the C++ standard.
istream& istr = false ? cin : ( * new ifstream("test.txt")) ;
Using g++ it compiles. Using MS VC 8 it fails with a message along the
lines of:
"cannot access private member declared in class...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |