public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96412] New: format suggestion issue
@ 2020-08-01 17:17 jg at jguk dot org
2020-08-02 20:36 ` [Bug c++/96412] " redi at gcc dot gnu.org
2022-12-26 21:22 ` jg at jguk dot org
0 siblings, 2 replies; 3+ messages in thread
From: jg at jguk dot org @ 2020-08-01 17:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96412
Bug ID: 96412
Summary: format suggestion issue
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jg at jguk dot org
Target Milestone: ---
Running on godbolt trunk
The suggestion is '%ld' in green type colour in the terminal, but should it
actually be '%zu' ?
-Wformat-signedness -Wall
#include <cstdio>
int main()
{
size_t i = 0;
printf("%ld\n", i);
}
#1 with x86-64 gcc (trunk)
<source>: In function 'int main()':
<source>:5:11: warning: format '%ld' expects argument of type 'long int', but
argument 2 has type 'size_t' {aka 'long unsigned int'} [-Wformat=]
5 | printf("%ld\n", i);
| ~~^ ~
| | |
| | size_t {aka long unsigned int}
| long int
| %ld
Compiler returned: 0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/96412] format suggestion issue
2020-08-01 17:17 [Bug c++/96412] New: format suggestion issue jg at jguk dot org
@ 2020-08-02 20:36 ` redi at gcc dot gnu.org
2022-12-26 21:22 ` jg at jguk dot org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-02 20:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96412
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Last reconfirmed| |2020-08-02
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Confirmed. If the conversion specification is "%d" it still recommends %ld for
size_t.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/96412] format suggestion issue
2020-08-01 17:17 [Bug c++/96412] New: format suggestion issue jg at jguk dot org
2020-08-02 20:36 ` [Bug c++/96412] " redi at gcc dot gnu.org
@ 2022-12-26 21:22 ` jg at jguk dot org
1 sibling, 0 replies; 3+ messages in thread
From: jg at jguk dot org @ 2022-12-26 21:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96412
--- Comment #2 from Jonny Grant <jg at jguk dot org> ---
Just posted this on bug 90205 but maybe more appropriate here
gcc (Ubuntu 12.2.0-3ubuntu1) 12.2.0
Another example, but suggesting the same %ld from a sizeof
printf("sizeof time_t %zu\n", sizeof(time_t));
broken.c:35:35: warning: format ‘%ld’ expects argument of type ‘long int’, but
argument 2 has type ‘long unsigned int’ [-Wformat=]
35 | printf("sizeof unsigned int %ld\n", sizeof(unsigned int));
| ~~^ ~~~~~~~~~~~~~~~~~~~~
| | |
| | long unsigned int
| long int
| %ld
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-26 21:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01 17:17 [Bug c++/96412] New: format suggestion issue jg at jguk dot org
2020-08-02 20:36 ` [Bug c++/96412] " redi at gcc dot gnu.org
2022-12-26 21:22 ` jg at jguk dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).