aboutsummaryrefslogtreecommitdiff
path: root/googletest/include
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@google.com>2016-12-21 20:40:58 -0500
committerDavid Benjamin <davidben@google.com>2016-12-21 20:57:21 -0500
commit53c478d639b8eebd2942e88266610ebc79c541f6 (patch)
tree3ce5fee40e4ed41903208461598b25dfcd599da4 /googletest/include
parent5e7fd50e17b6edf1cadff973d0ec68966cf3265e (diff)
downloadgoogletest-53c478d639b8eebd2942e88266610ebc79c541f6.tar.gz
Annotate ColoredPrintf with the format attribute and fix bugs.
googletest doesn't currently build with clang's very aggressive -Wformat-nonliteral warning. It requires that all non-literal format strings come from the argument of a function annotated with a compatible format attribute. Fixing that reports that ColoredPrintf's callers weren't passing the normal -Wformat warning. Some messages were passed directly into the format string rather than via "%s".
Diffstat (limited to 'googletest/include')
-rw-r--r--googletest/include/gtest/internal/gtest-port.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index 0d53ad27..b55ebf97 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -874,6 +874,23 @@ using ::std::tuple_size;
# define GTEST_ATTRIBUTE_UNUSED_
#endif
+// Use this annotation before a function that takes a printf format string.
+#if defined(__GNUC__) && !defined(COMPILER_ICC)
+# if defined(__MINGW_PRINTF_FORMAT)
+// MinGW has two different printf implementations. Ensure the format macro
+// matches the selected implementation. See
+// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/.
+# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
+ __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \
+ first_to_check)))
+# else
+# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
+ __attribute__((__format__(__printf__, string_index, first_to_check)))
+# endif
+#else
+# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
+#endif
+
// A macro to disallow operator=
// This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_ASSIGN_(type)\