https://llvm.org/bugs/show_bug.cgi?id=27495

            Bug ID: 27495
           Summary: Wrong warning about unspecified behavior for
                    comparison with string literal
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: chere...@mccme.ru
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

While compiling such program:

int main()
{
  "abc" == "def";
}

I get this warning:

$ clang -Wall -Wno-unused-value example.c 
example.c:3:9: warning: result of comparison against a string literal is
unspecified (use strncmp instead) [-Wstring-compare]
  "abc" == "def";
  ~~~~~ ^
1 warning generated.

The warning is wrong, this equality cannot be true.

I understand that the warning is intended to catch comparisons like "abc" ==
"abc" which indeed have an unspecified result. But the current warning is too
promiscuous.
The easy fix is to reformulate closer to "comparison with string literal is
always false or has an unspecified result".
The more thorough fix is to separately catch cases that could be proved to be
false at compile time.

gcc bug -- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70772 .

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to