Hi all,
The following code:
enum error_type_t {
none, warn, err, fatal
};
void error(error_type_t p_et, const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)))
;
class ErrorContext {
public:
ErrorContext();
ErrorContext(const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3))); // 'this' is at 1
~ErrorContext();
static void error(error_type_t p_et, const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)))
;
static void error_internal(const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 1, 2), __noreturn__));
};
int main(int argc, char **argv)
{
if (argc < 2 ) {
ErrorContext ec("While checking arguments");
if (argc < 1) {
ec.error_internal("argc=%d is not possible", argc);
}
ec.error(fatal, "Not enough arguments for %s", argv[0]); // line 34
error (fatal, "Not enough arguments for %s", argv[0]);
}
return 0;
}
and the following commandline
clang++ -c -Wformat=2 example.cc
generates a spurious warning:
example.cc:34:14: warning: format string is not a string literal
[-Wformat-nonliteral]
ec.error(fatal, "Not enough arguments for %s", argv[0]);
^~~~~
The handling of the static method "error" seems to be inconsistent
with the free function "error" (there is no warning for line 35).
$ clang++ --version
clang version 2.9 (trunk 119134)
Target: x86_64-unknown-linux-gnu
Thread model: posix