diff options
author | Harald Fernengel <harald.fernengel@nokia.com> | 2013-06-27 09:41:46 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-17 19:05:50 +0100 |
commit | e7d39c929204f631d11e2f87b2f8e972b1abbf6e (patch) | |
tree | 4ac3193d4e02aba6aad0c5464c648ad143ef1ba4 /src/corelib/global | |
parent | d1f8a5641615eb83bb36b4ada5913531d0da24f1 (diff) |
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>
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.h | 13 | ||||
-rw-r--r-- | src/corelib/global/qlogging.h | 49 |
2 files changed, 18 insertions, 44 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 3c3d35e373..9e2dce6d8c 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -462,6 +462,19 @@ typedef qptrdiff qintptr; # define QT_FASTCALL #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 //the alignment needs to be forced for sse2 to not crash with mingw #if defined(Q_OS_WIN) diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index 2b798f9ea0..5ae1fb3205 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -92,55 +92,16 @@ public: Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function, const char *category) : context(file, line, function, category) {} - void debug(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 - ; - 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 debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); + void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3) {} - void warning(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 - ; - 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 - ; + void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); + void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); #ifndef Q_CC_MSVC Q_NORETURN #endif - void fatal(const char *msg, ...) const Q_DECL_NOTHROW -#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 fatal(const char *msg, ...) const Q_DECL_NOTHROW Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); #ifndef QT_NO_DEBUG_STREAM QDebug debug() const; |