tsnorri
tsnorri

Reputation: 2097

Limiting -Wsuggest-attribute to certain files

GCC's C and C++ compilers have several useful warning options, such as

and so on. When I try to compile my code with these options, the compiler also issues warnings on the code in the (header-only) libraries that I use. Is there a way to apply the warnings only on my code, e.g. by listing the directories that include relevant files or by some other means?

Upvotes: 0

Views: 398

Answers (1)

Rainer Keller
Rainer Keller

Reputation: 355

You might want to look into GCC's Diagnostic pragmas -- these are supported in the following form since gcc-4.5.

After the #include of all library-headers you do not care about, add: #pragma GCC diagnostic warning "-Wsuggest-attribute=format" and further warnings to be enabled, to be warned of attributes to be added.

E.g. the following my_printf could use the attribute(format) specifier:

int my_printf(const char * format, ...) __attribute__((__format__(__printf__, 1, 2)));
int my_printf(const char * format, ...) {
    va_list ap;

    va_start(ap, format);
    vprintf (format, ap);
    va_end(ap);
    return 0;
}

Upvotes: 1

Related Questions