"Michael N. Moran" <[EMAIL PROTECTED]> writes:
| Gabriel Dos Reis wrote:
| > "Michael N. Moran" <[EMAIL PROTECTED]> writes:
| > | void bar(int& a);
| > | | void foo(int* a)
| > | {
| > | // dereference: conversion to reference
| > | // Since there is not necessarily any object access,
| > | // thus no assured SEGFAULT.
| > | bar(*a);
| > SEGFAULT is not a behaviour defined by the language.
|
| Even *I* know that, in spite of my lack of legal expertise.
It is not really a matter of legal expertise. It is just hard to pin
down where you're driving at.
| > It is *just* one form of undefined behaviour.
|
| Are you saying that this portion of the code *will*
| invoke undefined behavior even if the pointer "a"
| is valid?
I'm saying that if you call foo with a null pointer, you get into
undefined behaviour territory. And GCC is founded to make
optimization based on that. And you -- as a user -- generally don't
know how and when GCC can apply that assumption. And it is already
doing so in known cases; it may do more in the future. I don't want
to go and give a long list of the specific cases; there is no point in
it. The transformation is general and will be applied where the
opportunity arises. Just don't count on dereferencing a null pointer
to result you or not result in a segfault in general.
-- Gaby