[Bug c/70772] New: Wrong warning about unspecified behavior for comparison with string literal

ch3root at openwall dot com gcc-bugzilla@gcc.gnu.org
Sat Apr 23 18:40:00 GMT 2016


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

            Bug ID: 70772
           Summary: Wrong warning about unspecified behavior for
                    comparison with string literal
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ch3root at openwall dot com
  Target Milestone: ---

While compiling such program:

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

I get this warning:

$ gcc -Wall -Wno-unused-value example.c 
example.c: In function ‘main’:
example.c:3:9: warning: comparison with string literal results in unspecified
behavior [-Waddress]
   "abc" == "def";
         ^~

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.


More information about the Gcc-bugs mailing list