[LLVMbugs] [Bug 8625] New: Incorrect warning with -Wformat=2

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 16 00:17:28 PST 2010


           Summary: Incorrect warning with -Wformat=2
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: csaba_22 at yahoo.co.uk
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com

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 {


 ErrorContext(const char *fmt, ...)
   __attribute__ ((__format__ (__printf__, 2, 3))); // 'this' is at 1


 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
   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

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list