|
Bugzilla – Full Text Bug Listing |
| Summary: | gcc shouldn't warn when testing two distinct string literals for equality | ||
|---|---|---|---|
| Product: | [openSUSE] openSUSE 10.3 | Reporter: | Michal Marek <mmarek> |
| Component: | Development | Assignee: | Richard Biener <rguenther> |
| Status: | RESOLVED INVALID | QA Contact: | E-mail List <qa-bugs> |
| Severity: | Minor | ||
| Priority: | P5 - None | ||
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | Other | ||
| OS: | Other | ||
| Whiteboard: | |||
| Found By: | Other | Services Priority: | |
| Business Priority: | Blocker: | --- | |
| Marketing QA Status: | --- | IT Deployment: | --- |
| Attachments: | _untested_ patch for C | ||
Created attachment 110675 [details]
_untested_ patch for C
(In reply to comment #1) > Created an attachment (id=110675) [edit] > _untested_ patch for C Doesn't work :-/ It is not guaranteed that "string1" == "string1" (they are not required to be merged). So your program is not portable. In the example above, there are four _different_ strings, which will live at four different addresses. Of course if fixing this is too difficult, then feel free to close this again. Code like this isn't very common... The point I wanted to make is that comparison of string literals is pointless, so the warning is ok. I guess you want to avoid the warning if we can prove the result will be the same regardless of whether string literals are merged? If so, please file this upstream as an enhancement request or with fate. Thanks, Richard. |
$ cat cmp.c int f1(void) { return "string1" == "string2"; } int f2(void) { return "string3" != "string4"; } $ gcc -c -Wall cmp.c cmp.c: In function ‘f1’: cmp.c:3: warning: comparison with string literal cmp.c: In function ‘f2’: cmp.c:8: warning: comparison with string literal $ Not that code like this would fall into the category "good programming practice", but the expressions will work nevertheless.