On 30 Aug, Don Lewis wrote: > On 30 Aug, Kay Schenk wrote: >> >> >> On 08/29/2016 04:14 PM, Don Lewis wrote:
>>> A couple -Wtautological-undefined-compare warnings: >>> >>> warning: reference cannot be bound to dereferenced null pointer in >>> well-defined C++ code; comparison may be assumed to always evaluate to >>> false [-Wtautologica >>> l-undefined-compare] >>> if (&other == NULL) { >>> ^~~~~ ~~~~ >> >> This one is apparently an old holdoever from C and not recommended >> currently... >> >> See. e.g: >> http://stackoverflow.com/questions/17772103/can-i-use-if-pointer-instead-of-if-pointer-null >> >> It probably needs an update to accomplish what it's trying to do. >> >> >>> >>> warning: 'this' pointer cannot be null in well-defined C++ code; comparison >>> may be assumed to always evaluate to false [-Wtautological-undefin >>> ed-compare] >>> if(this == 0 || this == &src) { >>> ^~~~ ~ >>> >> >> Same here... > > nullptr is a c++11 thing and is not supported by older compilers. > > When I upgraded one of the bundled packages (nss?) I found it had some > test code that used nullptr that didn't compille on many of our > platforms. I had to disconnect the tests from the build. > > The warnings are about things that can't be null. In the first case if > you have a reference to another variable, then the address of that > variable can't be null. In the second case, this could only be null if > you call a method on a null object. > > One of the bits of code that I looked at for the first error looked > suspicious. It looks like it is passing *ptr as a reference parameter. > I'm not sure that's legal, and then the question is what happens if ptr > is null? Other calls to the same function were passing a regular > variable by reference. The appropriate fix in this case my be to create > a variant function that accepts a pointer and checks for NULL. Rather > than checking &ref == NULL. Hmn, this is what I was afraid of. The following code compiles without any warnings or errors: #include <stdio.h> void func(int &arg) { fprintf(stderr, "%p\n", &arg); } int main(void) { int i, *p1, *p2; i = 42; p1 = &i; p2 = NULL; func(*p1); func(*p2); } Running it gives the following output: 0x7fffffffea7c 0x0 So basically it is allowing *p2 to be dereferenced even though it is NULL, and the address of the reference variable inside func() is 0. I guess this isn't well defined C++ code ... <http://stackoverflow.com/questions/28689269/how-to-fix-reference-cannot-be-bound-to-dereferenced-null-pointer-warning> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org For additional commands, e-mail: dev-h...@openoffice.apache.org