public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50593] New: improve __attribute__((format(printf)))
@ 2011-10-02 21:58 b.r.longbons at gmail dot com
2011-10-03 8:54 ` [Bug c++/50593] " jakub at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: b.r.longbons at gmail dot com @ 2011-10-02 21:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
Bug #: 50593
Summary: improve __attribute__((format(printf)))
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: b.r.longbons@gmail.com
Created attachment 25398
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25398
8 tests
There are a number of cases where the compiler should be able to use a constant
string to check the arguments of a printf-like function.
Expected Result:
GCC always warns about format argument errors, when it can.
Actual Result:
GCC only warns in a couple of cases.
In particular, note:
* const char[] works in C but not C++.
* Directly using the result of a constexpr function doesn't work, but assigning
it to a variable does. (This is fortunate, because it allowed me to write the
most awesome code ever, a safe wrapper that allows passing e.g. a std::string
to printf!)
Versions tested:
All tests: 4.6.1 (gentoo), r179098 from branch 4.6, and trunk sometime near
that.
Tests 1,2,6,7,8 (without constexpr): 4.5.3, 4.4.6, 4.3.6 (gentoo)
Tests 1,2 (C++98): 4.2.4 (gentoo)
Tests 1,2 in C: all mentioned versions.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50593] improve __attribute__((format(printf)))
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
@ 2011-10-03 8:54 ` jakub at gcc dot gnu.org
2011-10-04 10:31 ` paolo.carlini at oracle dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-10-03 8:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-10-03 08:53:27 UTC ---
const char[] not working in C++ is PR38980.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50593] improve __attribute__((format(printf)))
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
2011-10-03 8:54 ` [Bug c++/50593] " jakub at gcc dot gnu.org
@ 2011-10-04 10:31 ` paolo.carlini at oracle dot com
2011-10-15 20:56 ` paolo.carlini at oracle dot com
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-04 10:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-04 10:30:44 UTC ---
Created attachment 25408
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25408
hacked patchlet
Indeed, this kind of hacked (*) patch fixes tests 2 and 6 here (doesn't fix
tests 7 and 8) and also tests @ lines 10 and 13 of PR38980 (doesn't fix
non-const tests there). I don't know if we want to build on it or we want to do
something more invasive touching code in gcc/ and in gcc/c-family...
(*) But safe, AFAICS, because at the moment, besides check_format_arg, no other
code in c-family actually used by the C++ front-end calls decl_constant_value.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50593] improve __attribute__((format(printf)))
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
2011-10-03 8:54 ` [Bug c++/50593] " jakub at gcc dot gnu.org
2011-10-04 10:31 ` paolo.carlini at oracle dot com
@ 2011-10-15 20:56 ` paolo.carlini at oracle dot com
2011-10-15 20:59 ` paolo.carlini at oracle dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-15 20:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-15 20:56:42 UTC ---
PR38980 bits fixed for 4.7.0. Maybe Jason can have a look to the constexpr
bits..
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50593] improve __attribute__((format(printf)))
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
` (2 preceding siblings ...)
2011-10-15 20:56 ` paolo.carlini at oracle dot com
@ 2011-10-15 20:59 ` paolo.carlini at oracle dot com
2011-10-15 21:17 ` [Bug c++/50593] [C++0x] " jason at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-15 20:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011-10-15
Ever Confirmed|0 |1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50593] [C++0x] improve __attribute__((format(printf)))
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
` (3 preceding siblings ...)
2011-10-15 20:59 ` paolo.carlini at oracle dot com
@ 2011-10-15 21:17 ` jason at gcc dot gnu.org
2011-10-15 21:57 ` paolo.carlini at oracle dot com
2011-11-08 21:59 ` david at rgmadvisors dot com
6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-10-15 21:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-10-15 21:16:47 UTC ---
Seems like it's a matter of changing check_format_arg to call a more general
front-end interface than decl_constant_value, one that could accept an
arbitrary expression rather than just a decl, and would call
maybe_constant_value.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50593] [C++0x] improve __attribute__((format(printf)))
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
` (4 preceding siblings ...)
2011-10-15 21:17 ` [Bug c++/50593] [C++0x] " jason at gcc dot gnu.org
@ 2011-10-15 21:57 ` paolo.carlini at oracle dot com
2011-11-08 21:59 ` david at rgmadvisors dot com
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-15 21:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-15 21:56:57 UTC ---
I see. I'll give it some thought.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50593] [C++0x] improve __attribute__((format(printf)))
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
` (5 preceding siblings ...)
2011-10-15 21:57 ` paolo.carlini at oracle dot com
@ 2011-11-08 21:59 ` david at rgmadvisors dot com
6 siblings, 0 replies; 8+ messages in thread
From: david at rgmadvisors dot com @ 2011-11-08 21:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50593
--- Comment #6 from David Oliver <david at rgmadvisors dot com> 2011-11-08 21:55:46 UTC ---
Created attachment 25760
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25760
8 Tests plus 1.
I've added test 9 to Ben's set which is a likely usage of the feature, e.g.
automatically converting std::string to a C string for printf().
Unsurprisingly, this case also fails on 4.6.2.
Cheers!
David.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-11-08 21:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-02 21:58 [Bug c++/50593] New: improve __attribute__((format(printf))) b.r.longbons at gmail dot com
2011-10-03 8:54 ` [Bug c++/50593] " jakub at gcc dot gnu.org
2011-10-04 10:31 ` paolo.carlini at oracle dot com
2011-10-15 20:56 ` paolo.carlini at oracle dot com
2011-10-15 20:59 ` paolo.carlini at oracle dot com
2011-10-15 21:17 ` [Bug c++/50593] [C++0x] " jason at gcc dot gnu.org
2011-10-15 21:57 ` paolo.carlini at oracle dot com
2011-11-08 21:59 ` david at rgmadvisors dot com
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).