On 17.03.2016 22:42, Richard wrote:
> [Please do not mail me a copy of your followup]
>
> Paavo Helde <
myfir...@osa.pri.ee> spake the secret code
> <
2JadnQ_YK8UqanfL...@giganews.com> thusly:
>
>> On 17.03.2016 18:45, Richard wrote:
>>> I don't see any undefined behavior here. What I see is an odr-use of
>>> a name that isn't defined.
>>
>> Sorry, I am not sure I am understanding what you wanted to say. An
>> odr-use of a name that is not defined is exactly what constitutes the
>> undefined behavior [...]
>
> I'm not sure how this constitutes undefined behavior, because the ODR
> rule says essentially that everything you use has to be defined.
>
> If you're just concluding "its UB because it doesn't say anything
> about it", then we have to go through the entire standard to draw that
> conclusion.
>
>> Anything which is not defined by the standard is undefined. The standard
>> only defines programs which contain exactly one definition of a
>> non-inline odr-used function. The programs which contain 2 or 0
>> definitions of such a function are not covered by the standard, i.e.
>> their behavior is undefined.
>
> This just seems like an awfully broad definition of UB with respect to
> the ODR rule.
This has nothing to do with the ODR rule, it's a general property of the
standard (and many other standards no doubt).
<quote>
1.3.24 [defns.undefined]
undefined behavior
behavior for which this International Standard imposes no requirements
[ Note: Undefined behavior may be expected when this International
Standard omits any explicit definition of`behavior [...].
Many erroneous program constructs do not engender undefined behavior;
they are required to be diagnosed.
</quote>
Coming back to the ODR rule, this is specifically mentioned as not to be
required to be diagnosed ("no diagnostic required"). I guess this is so
because the linker (which would be able to diagnose such errors) might
not be under the control of the compiler developers.
> Or perhaps it is just silly to do anything other than
> give a link error for symbols that are multiply defined or undefined
> when the ODR is broken. Hell, gcc ran nethack at one point, so while
> the compiler is technically free to do whatever it wants during
> undefined behavior, letting such undefined symbols slip through
> without an error feels highly unuseful.
The program works exactly the same as it would have worked when the
function had been defined, so I am not sure there is a good reason to
blame gcc here. On the other hand, there is no good reason to blame MSVC
either for not compiling the program.
Cheers
Paavo