public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107802] New: -Wsuggest-attribute=format ignores [[gnu::format(...)]]
@ 2022-11-22  7:19 adam.f.badura at gmail dot com
  2022-11-22 19:11 ` [Bug c/107802] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: adam.f.badura at gmail dot com @ 2022-11-22  7:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107802

            Bug ID: 107802
           Summary: -Wsuggest-attribute=format ignores
                    [[gnu::format(...)]]
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adam.f.badura at gmail dot com
  Target Milestone: ---

I checked the issue with GCC 10.2 and trunk as on Compiler Explorer using
arguments

 -std=c++17 -O3 -Wall -Wextra -Wpedantic -Wsuggest-attribute=format

The following code (https://godbolt.org/z/qP91h5Knv):

 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>

 __attribute__((format(printf, 4, 5))) [[noreturn]] void raise(
     [[maybe_unused]] const char* const file,
     [[maybe_unused]] const unsigned line,
     [[maybe_unused]] const char* const condition,
     const char* assertionMessage,
     ...)
 {
     std::fprintf(stderr, "*** Assertion message: ");
     va_list args;
     va_start(args, assertionMessage);
     std::vfprintf(stderr, assertionMessage, args);
     va_end(args);
     std::fprintf(stderr, "\n");

     std::abort();
 }

passes fine.

However, if we replace

 __attribute__((format(printf, 4, 5)))

with

 [[gnu::format(printf, 4, 5)]]

a warning shows up (https://godbolt.org/z/oecjj4Tzv):

 <source>: In function 'void raise(const char*, unsigned int, const char*,
const char*, ...)':
 <source>:15:49: warning: function 'void raise(const char*, unsigned int, const
char*, const char*, ...)' might be a candidate for 
 'gnu_printf' format attribute [-Wsuggest-attribute=format]
    15 |     std::vfprintf(stderr, assertionMessage, args);
       |                                                 ^

My overall experience is that the [[gnu::...]] syntax for attributes doesn't
behave the same as the __attribute__((...)) syntax. Not only it seems to be
more limited to where we can place it (this is up to C++, not GCC) but also it
seems attributes provided this way are more likely to be more or less ignored.
However, this is the first time I caught the issue so clearly.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-23  7:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22  7:19 [Bug c++/107802] New: -Wsuggest-attribute=format ignores [[gnu::format(...)]] adam.f.badura at gmail dot com
2022-11-22 19:11 ` [Bug c/107802] " pinskia at gcc dot gnu.org
2022-11-22 19:17 ` pinskia at gcc dot gnu.org
2022-11-23  6:10 ` adam.f.badura at gmail dot com
2022-11-23  7:45 ` pinskia at gcc dot gnu.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).