Introduce Q_ATTRIBUTE_FORMAT_PRINTF

Removes a lot of copy-paste code for flagging printf style functions.

Change-Id: Iecc1e312d1f28b5cbb6b297039f1cdbbc888f843
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Harald Fernengel 2013-06-27 09:41:46 +02:00 committed by The Qt Project
parent d1f8a56416
commit e7d39c9292
3 changed files with 20 additions and 62 deletions

View File

@ -462,6 +462,19 @@ typedef qptrdiff qintptr;
# define QT_FASTCALL # define QT_FASTCALL
#endif #endif
// enable gcc warnings for printf-style functions
#if defined(Q_CC_GNU) && !defined(__INSURE__)
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
__attribute__((format(gnu_printf, (A), (B))))
# else
# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
__attribute__((format(printf, (A), (B))))
# endif
#else
# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
#endif
//defines the type for the WNDPROC on windows //defines the type for the WNDPROC on windows
//the alignment needs to be forced for sse2 to not crash with mingw //the alignment needs to be forced for sse2 to not crash with mingw
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)

View File

@ -92,55 +92,16 @@ public:
Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function, const char *category) Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function, const char *category)
: context(file, line, function, category) {} : context(file, line, function, category) {}
void debug(const char *msg, ...) const void debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
#if defined(Q_CC_GNU) && !defined(__INSURE__) void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3)
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
__attribute__ ((format (gnu_printf, 2, 3)))
# else
__attribute__ ((format (printf, 2, 3)))
# endif
#endif
;
void noDebug(const char *, ...) const
#if defined(Q_CC_GNU) && !defined(__INSURE__)
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
__attribute__ ((format (gnu_printf, 2, 3)))
# else
__attribute__ ((format (printf, 2, 3)))
# endif
#endif
{} {}
void warning(const char *msg, ...) const void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
#if defined(Q_CC_GNU) && !defined(__INSURE__) void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
__attribute__ ((format (gnu_printf, 2, 3)))
# else
__attribute__ ((format (printf, 2, 3)))
# endif
#endif
;
void critical(const char *msg, ...) const
#if defined(Q_CC_GNU) && !defined(__INSURE__)
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
__attribute__ ((format (gnu_printf, 2, 3)))
# else
__attribute__ ((format (printf, 2, 3)))
# endif
#endif
;
#ifndef Q_CC_MSVC #ifndef Q_CC_MSVC
Q_NORETURN Q_NORETURN
#endif #endif
void fatal(const char *msg, ...) const Q_DECL_NOTHROW void fatal(const char *msg, ...) const Q_DECL_NOTHROW Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
#if defined(Q_CC_GNU) && !defined(__INSURE__)
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
__attribute__ ((format (gnu_printf, 2, 3)))
# else
__attribute__ ((format (printf, 2, 3)))
# endif
#endif
;
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QDebug debug() const; QDebug debug() const;

View File

@ -302,24 +302,8 @@ public:
const QString &a4, const QString &a5, const QString &a6, const QString &a4, const QString &a5, const QString &a6,
const QString &a7, const QString &a8, const QString &a9) const Q_REQUIRED_RESULT; const QString &a7, const QString &a8, const QString &a9) const Q_REQUIRED_RESULT;
QString &vsprintf(const char *format, va_list ap) QString &vsprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(2, 0);
#if defined(Q_CC_GNU) && !defined(__INSURE__) QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
__attribute__ ((format (gnu_printf, 2, 0)))
# else
__attribute__ ((format (printf, 2, 0)))
# endif
#endif
;
QString &sprintf(const char *format, ...)
#if defined(Q_CC_GNU) && !defined(__INSURE__)
# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
__attribute__ ((format (gnu_printf, 2, 3)))
# else
__attribute__ ((format (printf, 2, 3)))
# endif
#endif
;
int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;