The difference between Undefined Behavior and improper formation, no diagnostic message required

The C ++ standard comes with an amazing amount of definitions for fuzzy behavior 1 which means more or less the same with subtle differences. Reading this answer , I noticed that the wording "the program is poorly formed, no diagnostics are required."

Defined by the implementation differs from unspecified behavior in that the implementation in the first case should clearly document what it is doing (in the latter case it is not necessary), both of them are well-formed. Undefined behavior differs from unspecified in that the program is erroneous (1.3.13).
Otherwise, everyone has in common that the standard makes no assumptions or requirements as to what the implementation will do. With the exception of 1.4 / 8, which states that implementations can have extensions that do not change the behavior of well-formed programs, but are poorly formed in accordance with the standard, and the implementation should diagnose the use of these, but can subsequently continue compiling and executing the poorly-formed program.

A poorly formed program is otherwise defined as informal (excellent!). On the other hand, a well-formed program is defined as one that adheres to syntactic and diagnosable semantic rules. This, therefore, means that an incorrect program is one that breaks down either syntactic or semantic rules (or both). In other words, an incorrect program should not actually be compiled at all (how can one translate, for example, a program with incorrect syntax in any meaningful way?).

I would be inclined to think that the word “erroneous” also implies that the compiler must abort the assembly with an error message (in the end, it erroneously assumes an error), but the “Note” section in 1.3.13 explicitly allows something else including silently ignoring the problem (and compilers obviously do not break the build due to UB, most do not even warn by default).

It can also be assumed that the erroneous and poorly formed are the same, but the standard does not go into details if this is so, or what this word should mean.

Further, 1.4 states that

the appropriate implementation should [...] accept and correctly execute a well-formed program

and

If a program contains a violation of a rule that does not require diagnostics, [...] there are no implementation requirements for this program.

In other words, the corresponding implementation must accept a well-formed program, but it can also accept a poorly formed program, even without warning. In addition, if the program is poorly formed because it uses the extension.

The second paragraph says that anything combined with “no diagnosis needed” means that the specification has no requirements, which means that it is basically equivalent to “undefined behavior”, except that the mention of the erroneous is not mentioned.

What would be the intention to use a wording such as “poorly formed, not requiring diagnosis”?

The presence of “no diagnosis” suggests that it is identical (or basically identical?) To undefined behavior. In addition, since behavior defined by implementation and vague is defined as well-formed, it must be something else.

On the other hand, since an incorrect program violates syntactic / semantic rules, it should not actually compile. Which, however, combined with the “lack of the need for diagnostics” would mean that the compiler would be allowed to silently exit without warning, and after that you won’t be able to find the executable.

Is there a difference between “poorly formed, lack of diagnostics” and “undefined behavior”, or is it just a complex synonym for the same thing?




1 In the absence of better wording for collective behavior
+16
c ++ undefined-behavior language-lawyer
Mar 04 '14 at 18:45
source share
2 answers

The standard is not always agreed upon, as we would like, because it is a very large document written (in practice) by a number of different people, and despite all the evidence, the inconsistencies slip through. In the case of undefined (and errors in general), I think that there is an additional problem in that for most basic things (pointers, etc.), the C ++ standard inspires C. But C understands that all errors are undefined behavior. unless otherwise indicated, where as a standard, C ++ tries to adhere to the point of view that all errors require unless otherwise indicated. (Although they still need to consider the case where the standard does not specify behavior.) I think this explains the inconsistency in the wording.

Globally, inconsistency is regrettable, but in general, if the standard says that something is erroneous or poorly formed, then this requires diagnostics, if the standard does not say that it is not, or that this behavior is undefined. In something like “poorly formed, no diagnostics required”, “no diagnostic required”, because otherwise it will require diagnostics. As for the difference between “poorly formed”, there is no “Diagnostics required” and “undefined behavior”, no. The first is probably more common in cases where the code is incorrect, the second where it is a problem at runtime, but it is not Systematic. (Specification of one definition. Rule, it is clear that the compile-time problem ends with "then undefined behavior.")

+10
Mar 04 '14 at 19:14
source share

How it should be: things that are undefined do not cause problems if a particular program launch does not cause undefined behavior. For example. dereferencing a null pointer only destroys your day when your particular program starts up (characterized by its input: input / output, non-deterministic functions, such as hourly requests, etc.), it actually performs it, but it reverses, so it can display undefined even until it technically reaches dereferencing. (This is mainly where I can think of code permutations.)

While a poorly formed PDR is what the implementation should diagnose during translation, but may be unable due to various technical or theoretical limitations. For example. ODR will require the implementation to collect all entity definitions and compare them; but that massive resource is depleted. Some NDR things are not even computationally feasible. undefined behavior occurs when an implementation does not immediately diagnose this material.

In practice, undefined behavior applies to some strange cases that are not conditionalities. Some strange preprocessor problems cause undefined behavior. This is strange because they do not have a meaningful representation in the compiled program, so it is unclear what might cause them to execute.

However, this view still gives you a reasonable idea of ​​why the two terms exist.

+6
Mar 04 '14 at 18:56
source share



All Articles