]> granicus.if.org Git - re2c/commitdiff
Fixed GXX warning '-Wsuggest-attribute=format'.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 20 Jul 2015 21:14:12 +0000 (22:14 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 20 Jul 2015 21:14:12 +0000 (22:14 +0100)
g++ warns if function with '__attribute__((format (printf, ...)))'
has wrong number of arguments or argument type is wrong.

re2c/src/conf/msg.h
re2c/src/parse/scanner.h
re2c/src/util/attribute.h [new file with mode: 0644]

index 74c3398e733dc553315106cc6ac5a473e89d07d7..8a7f3c278d9387da94039a1fad65feb3bc9aff18 100644 (file)
@@ -1,9 +1,11 @@
 #ifndef _RE2C_CONF_MSG_
 #define _RE2C_CONF_MSG_
 
+#include "src/util/attribute.h"
+
 namespace re2c {
 
-void error (const char * fmt, ...);
+void error (const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 1, 2)));
 void error_encoding ();
 void usage ();
 void vernum ();
index 21e98e9143c891f3918ccdb4d7da183ccd02b4e4..15a83c596859cbe803d398f76093874ca94e188f 100644 (file)
@@ -8,6 +8,7 @@
 #include "src/globals.h"
 #include "src/parse/input.h"
 #include "src/parse/token.h"
+#include "src/util/attribute.h"
 #include "src/util/forbid_copy.h"
 #include "src/util/substr.h"
 
@@ -74,8 +75,8 @@ public:
        const std::string & get_fname () const;
        void set_in_parse(bool new_in_parse);
        void fatal_at(uint32_t line, uint32_t ofs, const char *msg) const;
-       void fatalf_at(uint32_t line, const char*, ...) const;
-       void fatalf(const char*, ...) const;
+       void fatalf_at(uint32_t line, const char*, ...) const RE2C_GXX_ATTRIBUTE ((format (printf, 3, 4)));
+       void fatalf(const char*, ...) const RE2C_GXX_ATTRIBUTE ((format (printf, 2, 3)));
        void fatal(const char*) const;
        void fatal(uint32_t, const char*) const;
 
diff --git a/re2c/src/util/attribute.h b/re2c/src/util/attribute.h
new file mode 100644 (file)
index 0000000..027a607
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef _RE2C_UTIL_ATTRIBUTE_
+#define _RE2C_UTIL_ATTRIBUTE_
+
+#ifdef __GNUC__
+#    define RE2C_GXX_ATTRIBUTE(x) __attribute__(x)
+#else
+#    define RE2C_GXX_ATTRIBUTE(x)
+#endif
+
+#endif // _RE2C_UTIL_ATTRIBUTE_