PanHao000 / sparsehash

Automatically exported from code.google.com/p/sparsehash
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[PATCH] Fix gcc warning: format '%p' expects argument of type 'void*' #94

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Compile some code using sparsetable
2. Get warnings along the following lines:

warning: format '%p' expects argument of type 'void*', but argument 4 has type 
'google::sparsegroup<nest::Node*, 48u, 
google::libc_allocator_with_realloc<nest::Node*> 
>::alloc_impl<google::libc_allocator_with_realloc<nest::Node*> >::pointer {aka 
nest::Node**}' [-Wformat]

What is the expected output? What do you see instead?

No warnings.

What version of the product are you using? On what operating system?

Latest SVN.

Please provide any additional information below.

According to the standard, the format specifier '%p' expects a 'void*' pointer, 
however, as far as I understand, giving an argument of a different type is an 
undefined behavior, even though an implicit conversion can be safely performed, 
which is why gcc emits a warning.

The solution is to perform the conversion explicitly; I have chosen 'const 
void*', because I've seen it used in gcc itself, so I would assume that it's a 
good style:

http://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/iq2000/iq2000.c?r1=192717&r2=192
716&pathrev=192717

Please see the attached patch, which fixes this problem for me.

Original issue reported on code.google.com by yury.v.zaytsev on 14 Aug 2013 at 8:05

Attachments: