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

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 16 02:17:28 CST 2010


http://llvm.org/bugs/show_bug.cgi?id=8625

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

-- 
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 LLVMbugs mailing list