Bug 79616 - nonsense types in printf() format warnings
Summary: nonsense types in printf() format warnings
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 8.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2002-12-14 00:50 UTC by David Nečas
Modified: 2007-04-18 16:49 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2004-10-03 10:58:59 UTC

Attachments (Terms of Use)

Description David Nečas 2002-12-14 00:50:18 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021128

Description of problem:
printf() format warnings for %p (and %s and %n) format printed with -pedantic
shows bad variable types, one level of pointerness is missing.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. create a p.c file with following contents:

#include <stdio.h>
int main(void) {
  double *a, **b;
  printf("%p, %p\n", a, b);
  return 0;

2. compile it

gcc -c -Wall -pedantic p.c


Actual Results:
p.c: In function `main':
p.c:4: warning: void format, double arg (arg 2)
p.c:4: warning: void format, pointer arg (arg 3)

Expected Results:  Hard to say.  What I definitely don't expect is the `double
arg' on the second line, when arg 2 is POINTER to a double, not a double.

So expected result is anything between no warnings (when I'm printing pointers
with %p one is as good as another) and fully descriptive warning like (crazy,
but the kind of thing one expects from -pedantic):

p.c: In function `main':
p.c:4: warning: void* format, double* arg (arg 2)
p.c:4: warning: void* format, double** arg (arg 3)

Additional info:
While `double arg' corresponds to `void format' in the warning in the sense both
have one level of pointerness removed, it's confusing compared to

printf("%d", *a);

which prints

p.c:5: warning: int format, double arg (arg 2)

Both *a and a can't be double simultaneously.

The same happens for %s and %n conversion specifiers.

Comment 1 Richard Henderson 2004-10-03 10:58:59 UTC
The same bad wording persists through gcc 3.4; gcc 4.0 will generate 

z.c:4: warning: format '%p' expects type 'void *', but argument 2 has
type 'double *'
z.c:4: warning: format '%p' expects type 'void *', but argument 3 has
type 'double **'

Note You need to log in before you can comment on or make changes to this bug.