core: enable printf format warnings for cv::format
authorPavel Rojtberg <rojtberg@gmail.com>
Sun, 5 Aug 2018 23:23:19 +0000 (01:23 +0200)
committerMaksim Shabunin <maksim.shabunin@gmail.com>
Mon, 24 Sep 2018 08:31:40 +0000 (11:31 +0300)
modules/core/include/opencv2/core/operations.hpp

index 0d28b6c..8e9d013 100644 (file)
 
 #include <cstdio>
 
+#if defined(__GNUC__) || defined(__clang__) // at least GCC 3.1+, clang 3.5+
+#  define CV_FORMAT_PRINTF(string_idx, first_to_check) __attribute__ ((format (printf, string_idx, first_to_check)))
+#else
+#  define CV_FORMAT_PRINTF(A, B)
+#endif
+
 //! @cond IGNORED
 
 namespace cv
@@ -387,7 +393,7 @@ The function acts like sprintf but forms and returns an STL string. It can be us
 message in the Exception constructor.
 @param fmt printf-compatible formatting specifiers.
  */
-CV_EXPORTS String format( const char* fmt, ... );
+CV_EXPORTS String format( const char* fmt, ... ) CV_FORMAT_PRINTF(1, 2);
 
 ///////////////////////////////// Formatted output of cv::Mat /////////////////////////////////