K
Kiuhnm
#include <new>
class T
{
};
int main()
{
T t = t;
T u(u);
T v;
new (&v) T(v);
}
Kiuhnm
class T
{
};
int main()
{
T t = t;
T u(u);
T v;
new (&v) T(v);
}
Kiuhnm
Kiuhnm said:#include <new>
class T
{
};
int main()
{
T t = t;
T u(u);
T v;
new (&v) T(v);
}
Kiuhnm
Have you tried compiling this?
What do you expect each line to do?
Kiuhnm said:Ben Pope ha scritto:
Yes, but it is irrelevant. How can I be sure that my compiler is
completely standard-compliant?
It is irrelevant.
All I would like to know is whether the code, according to the standard,
produces a defined behavior or not.
Kiuhnm said:Ben Pope ha scritto:
Yes, but it is irrelevant. How can I be sure that my compiler is
completely standard-compliant?
It is irrelevant.
All I would like to know is whether the code, according to the standard,
produces a defined behavior or not.
Not.
T t = t;
T u(u);
The above two lines will compile but the behavior is undefined.
Please, why do you ask?
Kiuhnm" <"kiuhnm03[ said: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;
?
Kiuhnm said:#include <new>
class T
{
};
int main()
{
T t = t;
T u(u);
T v;
new (&v) T(v);
}
Dietmar said: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".
What's the difference from
T t = t;
do you see here?
Then "int x = x;" is /not/ undefined (e.g. a standard-compliant compiler
cannot format your hard disk).
Kiuhnm said:Victor Bazarov ha scritto:What's the difference from
T t = t;
do you see here?
T may not be a built-in type.
Anyway, my question was subtler than you think:
excerpt from c++ iso/iec 14882:3.3.1 Point of declaration
The /point of declaration/ for a name is immediately after its complete
declarator (clause 8) and before its /initializer/ (if any), except as
noted below.
[Example:
int x = 12;
{ int x = x; }
Here the second x is initialized with its own (indeterminate) value.]
<<<
Then "int x = x;" is /not/ undefined (e.g. a standard-compliant compiler
cannot format your hard disk).
It doesn't say that. It just says that, when the right hand side is
evaluated, the name 'x' already exists. It doesn't say anything about the
behavior of initializing x with an indeterminate value.
* Kiuhnm:
Using an indeterminate value, for anything, is formally UB.
I am just copying it (we cannot overload operator= for built-in types).
Alf P. Steinbach ha scritto:
I am just copying it (we cannot overload operator= for built-in types).
Alf said:* Kiuhnm:
Using an indeterminate value, for anything, is formally UB.
Kiuhnm said:Rolf Magnus ha scritto:It doesn't say that. It just says that, when the right hand side is
evaluated, the name 'x' already exists. It doesn't say anything about the
behavior of initializing x with an indeterminate value.
3.3.1#1:
"[...]Here the second x is initialized with its own (indeterminate)
value."
Alf said:* Kiuhnm:
Using an indeterminate value, for anything, is formally UB.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.