Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: Strange code-generation Date: Sat, 09 Nov 2019 05:52:50 -0800 Organization: A noiseless patient Spider Lines: 54 Message-ID: <86y2wpcg25.fsf@linuxsc.com> References: <867e654ndj.fsf@linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="bd07fdb0e7610947dc98257bdadc7724"; logging-data="9605"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sBvW0aku9wJbO3YoS+V/mWfk7cmk6b4Q=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:YwB1dKR+Izmq3ppXTj0u6yj6etY= sha1:D/+63RuH5AzkpLX/Gf5JU94+eq8= Xref: csiph.com comp.lang.c++:69676 Paavo Helde writes: > On 18.09.2019 18:47, Tim Rentsch wrote: > >> Paavo Helde writes: >> >>> In standard C++ one cannot legally construct a "null reference", so >>> the standard cannot mandate any behavior regarding them. [...] >> >> Sure it could. The Standard doesn't say that they can't exist, >> and even if they couldn't exist the Standard could still specify >> a behavior for how they must be treated. And it might even be >> useful to give such a specification, for implementations that >> choose to provide null references by means of an extension. > > By that logic the C++ standard could also prescribe how the SQL > language or the invisible unicorn in my garage must behave, in the > case someone happens to incorporate them into their C++ > implementation. These analogies are pretty much meaningless, because the terms are not in the universe of discourse for the C++ language. The term "reference" is in the C++ universe of discourse, and every C++ programmer understands what "null reference" means, in that context, by analogy with "null pointer". In fact the term "null reference" appears in the C++ standard, as you point out. > More to the point, the standard contains the following verbiage: > "A reference shall be initialized to refer to a valid object or > function. [ Note: in particular, a null reference cannot exist in a > well-defined program, because the only way to create such a reference > would be to bind it to the ?object? obtained by indirection through a > null pointer, which causes undefined behavior. ]" Saying "a null reference cannot exist in a well-defined program" is a circular statement; it has no information content, because of what is meant by well-defined. Also, just because a construct has undefined behavior doesn't mean the result can't exist. Obviously it can exist, because the implementation is free to define the meaning. > Without contradicting itself, the standard cannot say in one place "A > reference shall be initialized to refer to a valid object" and > "behavior is undefined" and then go on and discuss in another place > what happens if a program violates this "shall", thus defining the > behavior. There is no contradiction. What would (hypothetically) be being defined is not declaring/initializing a null reference, but using a null reference. Do you not understand the distinction? (Sorry to be so long in responding, life has been unusually chaotic of late.)