public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95149] New: lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
@ 2020-05-15 10:26 marxin at gcc dot gnu.org
2020-05-15 10:32 ` [Bug c++/95149] " jakub at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-05-15 10:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95149
Bug ID: 95149
Summary: lex.c:1729:8: warning: result of comparison against a
string literal is unspecified (use an explicit string
comparison function instead) [-Wstring-compare]
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
CC: jason at gcc dot gnu.org, nathan at gcc dot gnu.org
Target Milestone: ---
I see the following Clang warnings for lex.c. It comes from:
1729: BUF_APPEND ("\\", 1);
#define BUF_APPEND(STR,LEN) \
do { \
bufring_append (pfile, (const uchar *)(STR), (LEN), \
&first_buff, &last_buff); \
total_len += (LEN); \
if (__builtin_expect (temp_buffer_len < 17, 0) \
&& (const uchar *)(STR) != base \
&& (LEN) <= 2) \
{ \
memcpy (temp_buffer + temp_buffer_len, \
(const uchar *)(STR), (LEN)); \
temp_buffer_len += (LEN); \
} \
} while (0)
If I see correctly the problematic comparison is '(const uchar *)(STR) != base'
which is really a comparison in between a string literal and a local variable.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/95149] lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
2020-05-15 10:26 [Bug c++/95149] New: lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] marxin at gcc dot gnu.org
@ 2020-05-15 10:32 ` jakub at gcc dot gnu.org
2020-05-15 10:36 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-15 10:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95149
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
And?
It is unspecified if "foo" == "foo", not whether "foo" can compare equal to an
automatic variable (it can't).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/95149] lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
2020-05-15 10:26 [Bug c++/95149] New: lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] marxin at gcc dot gnu.org
2020-05-15 10:32 ` [Bug c++/95149] " jakub at gcc dot gnu.org
@ 2020-05-15 10:36 ` jakub at gcc dot gnu.org
2020-05-15 11:09 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-15 10:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95149
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
With string merging even "foobar" + 3 == "bar" (or not, depending on alignment
decision, how hard does the linker optimize etc.). For static vars only if
-fmerge-all-constants and the var would be const and contain the same chars.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/95149] lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
2020-05-15 10:26 [Bug c++/95149] New: lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] marxin at gcc dot gnu.org
2020-05-15 10:32 ` [Bug c++/95149] " jakub at gcc dot gnu.org
2020-05-15 10:36 ` jakub at gcc dot gnu.org
@ 2020-05-15 11:09 ` pinskia at gcc dot gnu.org
2020-05-19 18:41 ` nathan at gcc dot gnu.org
2020-05-19 19:27 ` marxin at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-15 11:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95149
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code here is correct. In that the warning might be valid for normal code
but the comparasion it is making is valid one.
Mainly because we do:
/* Restore backslash followed by newline. */
BUF_APPEND (base, cur - base);
base = cur;
BUF_APPEND ("\\", 1);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/95149] lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
2020-05-15 10:26 [Bug c++/95149] New: lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] marxin at gcc dot gnu.org
` (2 preceding siblings ...)
2020-05-15 11:09 ` pinskia at gcc dot gnu.org
@ 2020-05-19 18:41 ` nathan at gcc dot gnu.org
2020-05-19 19:27 ` marxin at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: nathan at gcc dot gnu.org @ 2020-05-19 18:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95149
Nathan Sidwell <nathan at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|UNCONFIRMED |RESOLVED
--- Comment #4 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Fixed ed63c387aa0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/95149] lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
2020-05-15 10:26 [Bug c++/95149] New: lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] marxin at gcc dot gnu.org
` (3 preceding siblings ...)
2020-05-19 18:41 ` nathan at gcc dot gnu.org
@ 2020-05-19 19:27 ` marxin at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-05-19 19:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95149
--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Nathan Sidwell from comment #4)
> Fixed ed63c387aa0
g:ed63c387aa0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-05-19 19:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 10:26 [Bug c++/95149] New: lex.c:1729:8: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] marxin at gcc dot gnu.org
2020-05-15 10:32 ` [Bug c++/95149] " jakub at gcc dot gnu.org
2020-05-15 10:36 ` jakub at gcc dot gnu.org
2020-05-15 11:09 ` pinskia at gcc dot gnu.org
2020-05-19 18:41 ` nathan at gcc dot gnu.org
2020-05-19 19:27 ` marxin at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).