On 12 Nov 2021 14:54, Juha Nieminen wrote:
With std::vector<T, Allocator>, if Allocator::value_type is not the same
as T, the behavior is undefined until C++20. Since C++20 the "program is
ill-formed".
What is the difference?
The in-practice:
UB can compile, with or without a diagnostic. Some/most kinds of UB are dynamic events during program execution, such as integer division by 0, dereferencing a nullpointer outside a `typeid` expressions, etc. It
would be impossible for a compiler to diagnose them all.
Ill formed program doesn't compile, and always causes a diagnostic.
The formal:
"Undefined Behavior" is (C++17 3.27) "behavior for which this
International Standard imposes no requirements".
"Ill formed" is just "not well formed", where "well formed" is just a
(C++17 §3.29) "program constructed according to the syntax rules,
diagnosable semantic rules, and the one-definition rule".
With std::vector<T, Allocator>, if Allocator::value_type is not the same
as T, the behavior is undefined until C++20. Since C++20 the "program is ill-formed".
What is the difference?
Alf P. Steinbach <alf.p.steinbach@gmail.com> wrote:
On 12 Nov 2021 14:54, Juha Nieminen wrote:
With std::vector<T, Allocator>, if Allocator::value_type is not the same >>> as T, the behavior is undefined until C++20. Since C++20 the "program is >>> ill-formed".
What is the difference?
The in-practice:
UB can compile, with or without a diagnostic. Some/most kinds of UB are
dynamic events during program execution, such as integer division by 0,
dereferencing a nullpointer outside a `typeid` expressions, etc. It
would be impossible for a compiler to diagnose them all.
Ill formed program doesn't compile, and always causes a diagnostic.
The formal:
"Undefined Behavior" is (C++17 3.27) "behavior for which this
International Standard imposes no requirements".
"Ill formed" is just "not well formed", where "well formed" is just a
(C++17 §3.29) "program constructed according to the syntax rules,
diagnosable semantic rules, and the one-definition rule".
So that means that starting from C++20 we are guaranteed to get a
compiler error if Allocator::value_type is not the same as T?
With std::vector<T, Allocator>, if Allocator::value_type is not the same
as T, the behavior is undefined until C++20. Since C++20 the "program is ill-formed".
What is the difference?
On 11/12/21 8:54 AM, Juha Nieminen wrote:
With std::vector<T, Allocator>, if Allocator::value_type is not the same
as T, the behavior is undefined until C++20. Since C++20 the "program is
ill-formed".
What is the difference?
When the behavior is undefined, the standard imposes no requirements
(3.30). Code which has undefined behavior is not considered to have
violated a diagnosable rule (4.1p1).
When a program is ill-formed, that qualifies as a violation of a
diagnosable rule, and as such, the standard imposes one requirement:
that at least one diagnostic message be generated.(4.1p2).
Ill formed program doesn't compile, and always causes a diagnostic.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
[...]
Ill formed program doesn't compile, and always causes a diagnostic.
The C++ standard identifies several sets of circumstances that
cause a program to be ill formed, but explicitly and specifically
do not require a diagnostic.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
[...]
Ill formed program doesn't compile, and always causes a diagnostic.
The C++ standard identifies several sets of circumstances that
cause a program to be ill formed, but explicitly and specifically
do not require a diagnostic.
On 13 Nov 2021 19:26, Tim Rentsch wrote:
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
[...]
Ill formed program doesn't compile, and always causes a diagnostic.
The C++ standard identifies several sets of circumstances that
cause a program to be ill formed, but explicitly and specifically
do not require a diagnostic.
Oh you're right, thanks. Sorry.
I was talking about the in-practice but clearly some ill formed programs can't even practically be diagnosed as such.
The difference between UB and ill-formed gets less clear then, but
mainly that UB is well formed code that isn't constrained to any
behavior, while ill formed code -- is code that isn't well formed and
that isn't constrained to any behavior. A bit too circular for me. But I guess syntactically invalid code must be ill-formed and cannot have UB.
14.11.2021 16:43 Alf P. Steinbach kirjutas:
On 13 Nov 2021 19:26, Tim Rentsch wrote:
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
[...]
Ill formed program doesn't compile, and always causes a diagnostic.
The C++ standard identifies several sets of circumstances that
cause a program to be ill formed, but explicitly and specifically
do not require a diagnostic.
Oh you're right, thanks. Sorry.
I was talking about the in-practice but clearly some ill formed
programs can't even practically be diagnosed as such.
The difference between UB and ill-formed gets less clear then, but
mainly that UB is well formed code that isn't constrained to any
behavior, while ill formed code -- is code that isn't well formed
and that isn't constrained to any behavior. A bit too circular for
me. But I guess syntactically invalid code must be ill-formed and
cannot have UB.
"UB" is behavior which is undefined by the C++ standard. Another
standard or the implementation can define the behavior, making the
program valid.
I suspect "ill-formed" is meant for programs which cannot or should
not be made valid by another standard or implementation.
On 13 Nov 2021 19:26, Tim Rentsch wrote:
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
[...]
Ill formed program doesn't compile, and always causes a diagnostic.
The C++ standard identifies several sets of circumstances that
cause a program to be ill formed, but explicitly and specifically
do not require a diagnostic.
Oh you're right, thanks. Sorry.
I was talking about the in-practice but clearly some ill formed
programs can't even practically be diagnosed as such.
The difference between UB and ill-formed gets less clear then, but
mainly that UB is well formed code that isn't constrained to any
behavior, while ill formed code -- is code that isn't well formed
and that isn't constrained to any behavior. A bit too circular
for me. But I guess syntactically invalid code must be ill-formed
and cannot have UB.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 113 |
Nodes: | 8 (1 / 7) |
Uptime: | 45:19:18 |
Calls: | 2,499 |
Calls today: | 1 |
Files: | 8,655 |
Messages: | 1,908,734 |