@Cubbi thanks for the explanation, I'm actually trying my best to be very subjective and non-biased, because to me both sides seem to have very good and valid points. That's why I said I was
leaning toward hamsterman's theory more (never said I believed it's 100% the truth) because that question about dangling references went unanswered and no one seems to have been addressing it. Basically I've read through all the posts, and I try to analyze and ask myself questions after every explanation. Like is that possible? Then try to see if the different cases support both the theories presented.
For me I'm just trying to prove it to myself, and I'm not trying to prove anyone wrong at all. Also, I don't believe that if a lot more people believe in certain things that those ideas are automatically correct. The chinese proverb "what is popular is not always right" is what makes me believe it's not merely a popularity contest. For example, in the time of Galileo most believed the Earth was the center of the universe but it didn't make them right. So, if a theory fails in even a single case then how can I believe it to be true? It would just make me feel like I'm lying to myself if I did.
Anyway, back on topic, your answer made me think of another question.
It's hard to make sense of this, given loose wording, but I *think* the first sentence meant to say: "undefined behavior occurs when accessing dangling references - references to objects whose lifetime has ended." This is only partially true (like most premises in FQA): there are both well-defined and undefined operations on such references (technically, on the lvalues such references evaluate to: §3.8[basic.life]/6-7). |
I believe, what it's trying to say is basically if a reference is indeed the object then once the object gets destroyed the reference should also be destroyed, if it is indeed the same object. So because of that case, the theory "the reference is an object" seem somewhat shaky in my opinion.
Secondly, I think you are saying that accessing a dangling reference leads to partial undefined behavior if I'm not mistaken? Doesn't that seem similar to dangling pointers too? Here's what wikipedia says about dangling pointers.
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. |
It seems very similar to dangling references I mean. And as hamsterman's theory goes "references are just hidden pointers".
Is it possible that if it is a hidden pointer like hamsterman says it is, that this could very well be the same reason for the undefined behavior when trying to access a dangling reference, and the partial well-defined behavior is just something the compiler adds to make it somewhat safer similar to Java in a sense? Or is there something I'm missing or completely wrong about with that idea?