Bug 26542 - bogus diagnostic with -pedantic?: format '%p'; expects type 'void*', but argument 2 has type 'A*'
Summary: bogus diagnostic with -pedantic?: format '%p'; expects type 'void*', but argu...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 28459 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-03 09:50 UTC by Pawel Sikora
Modified: 2009-02-10 23:15 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-03-03 11:50:54


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2006-03-03 09:50:16 UTC
$ g++ warn.cpp -Wall -ansi
no warnings.

$ g++ warn.cpp -Wall -pedantic
(...) format ‘%p’ expects type ‘void*’, but argument 2 has type ‘A*’


#include <cstdio>
struct A {};
int main()
{
    A* a = 0;
    printf("a = 0x%p\n", a);
    return 0;
}
Comment 1 Richard Biener 2006-03-03 11:50:54 UTC
Indeed.  Not exactly useful.
Comment 2 Andrew Pinski 2006-03-03 12:45:23 UTC
Actually the C standard says void* only.  I don't see the issue here.
Comment 3 Andrew Pinski 2006-03-03 14:07:45 UTC
This is actually expected.  From the C standard:
p The argument shall be a pointer to void. The value of the pointer is 
converted to a sequence of printing characters, in an implementation-defined 
manner. 


Comment 4 Vadim Zeitlin 2006-07-24 17:02:58 UTC
I'd like to (probably uselessly but still) argue for reopening this bug and removing this warning. The interpretation of the standard text is open to questions: IMHO an "A *" pointer is a pointer to void, too, as any pointer in C is, implicitely, pointer to void. But most importantly I think this warning is absolutely useless and the only way to get rid of it is ugly (you need an explicit cast to "void *").

But, again, the most important argument against this warning is that it's 100% useless. Conversion of any pointer to "void *" is well defined and unambiguous (even in presence of multiple inheritance) and there is just no situation whatsoever in which this warning can indicate a real problem. Please consider suppressing it, thanks in advance!
Comment 5 Pawel Sikora 2006-07-24 17:16:30 UTC
*** Bug 28459 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2006-12-08 04:37:43 UTC
> I'd like to (probably uselessly but still) argue for reopening this bug and
> removing this warning. The interpretation of the standard text is open to
> questions: IMHO an "A *" pointer is a pointer to void, too, as any pointer in C
> is, implicitely, pointer to void. But most importantly I think this warning is
> absolutely useless and the only way to get rid of it is ugly (you need an
> explicit cast to "void *").

Except IIRC a target could have void* pass different from a char* when it comes to var-args so really the warning is still correct.
Comment 7 Vadim Zeitlin 2006-12-08 11:07:48 UTC
Just for my personal education, could you please tell which target(s) pass "char *" differently from "void *" in this context?

Thanks!
Comment 8 pinskia@gmail.com 2006-12-08 18:17:40 UTC
Subject: Re:  bogus diagnostic with -pedantic?: format '%p';
	expects type 'void*', but argument 2 has type 'A*'

On Fri, 2006-12-08 at 11:07 +0000, vz-gcc at zeitlins dot org wrote:
> Just for my personal education, could you please tell which target(s)
> pass
> "char *" differently from "void *" in this context? 

A made up target (at least for now). :)


-- Pinski

Comment 9 Jason Orendorff 2009-02-10 22:22:55 UTC
Please consider reopening this bug.

I appreciate that the relevant standards don't guarantee this idiom will always work.  On the other hand, this warning is in practice only a nuisance.  Balance the real work this makes for people who try to keep their code pedantic-clean against the risk that someday an architecture will come along where it matters.

Could we maybe delete this warning just until we have some reason to believe that such an architecture is likely to exist someday, and then reinstate it?