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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to