Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(749)

Unified Diff: base/compiler_specific.h

Issue 339059: Add compiler-specific "examine printf format" attributes to printfs. (Closed)
Patch Set: cleanups Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/format_macros.h » ('j') | base/string_util_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/compiler_specific.h
diff --git a/base/compiler_specific.h b/base/compiler_specific.h
index 50dc6f348ae4813576baf7b53ed5c50ff75fb697..23b9f1242364c9708c8cdadb58476a821f84ccd8 100644
--- a/base/compiler_specific.h
+++ b/base/compiler_specific.h
@@ -67,11 +67,32 @@
#if defined(COMPILER_GCC)
+
#define ALLOW_UNUSED __attribute__((unused))
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+
+// Tell the compiler a function is using a printf-style format string.
+// |format_param| is the one-based index of the format string parameter;
+// |dots_param| is the one-based index of the "..." parameter.
+// For v*printf functions (which take a va_list), pass 0 for dots_param.
+// (This is undocumented but matches what the system C headers do.)
+#define PRINTF_FORMAT(format_param, dots_param) \
+ __attribute__((format(printf, format_param, dots_param)))
+
+// WPRINTF_FORMAT is the same, but for wide format strings.
+// This doesn't appear to yet be implemented.
+// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 .
+#define WPRINTF_FORMAT(format_param, dots_param)
+// If available, it would look like:
+// __attribute__((format(wprintf, format_param, dots_param)))
+
#else // Not GCC
+
#define ALLOW_UNUSED
#define WARN_UNUSED_RESULT
+#define PRINTF_FORMAT(x, y)
+#define WPRINTF_FORMAT(x, y)
+
#endif
#endif // BASE_COMPILER_SPECIFIC_H_
« no previous file with comments | « no previous file | base/format_macros.h » ('j') | base/string_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698