[LLVMbugs] [Bug 3753] New: clang should warn about comparison with string literal

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sat Mar 7 13:04:55 PST 2009


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

           Summary: clang should warn about comparison with string literal
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Semantic Analyzer
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: sharparrow1 at yahoo.com
                CC: llvmbugs at cs.uiuc.edu


Constructs like the following should emit a warning a comparison with a string
literal is almost certainly a mistake.  Comparing addresses of string literals
within the same file is probably safe, and comparing addresses across files is
likely to work, but most uses are probably not intentional.

First draft of wording:
warning: result of comparison with pointer to string literal is unspecified.

I was considering putting in a suggestion to use strcmp or something like that,
but it's hard to come up with wording that concise and doesn't sound insulting
to experienced programmers.

Examples:

>From a mailing list message:
if (@encode(__typeof__(a1)) != @encode(__typeof__(a2))) { ... }

One example from thousands of results from a Google Code Search for !=" :
if (!a->name.isEmpty() && a->type!="void") { ... }

gcc has a similar warning when -Wall is used, but they apparently missed the
case of @encode.


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