[lldb-dev] [Bug 20606] New: std::string vs. string literal comparison through "expr" command fails
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sat Aug 9 14:16:27 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20606
Bug ID: 20606
Summary: std::string vs. string literal comparison through
"expr" command fails
Product: lldb
Version: unspecified
Hardware: HP
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: lldb-dev at cs.uiuc.edu
Reporter: rdsmith at chromium.org
Classification: Unclassified
Created attachment 12872
--> http://llvm.org/bugs/attachment.cgi?id=12872&action=edit
Source file for reproduction
If you try and execute C++ code comparing a std::string with a string literal
using "expr", you get a warning and and error:
(lldb) expr abc == "abc"
error: warning: result of comparison against a string literal is unspecified
(use strncmp instead)
error: invalid operands to binary expression ('string' (aka
'std::basic_string<char, std::char_traits<char>, std::allocator<char> >') and
'const char *')
error: 1 errors parsing expression
(lldb)
That comparison works fine when compiled by clang++, despite the fact that the
first warning comes from the clang library
(tools/clang/lib/Sema/SemaExpr.cpp:7960 at r215285). I poked around in that
function, and it seems like it's designed to warn against string literal
comparison in the large majority of cases (including this one). So the
confusing thing here may be that clang++ doesn't warn about the comparison when
compiling (though I think that is the proper behavior, since std::string
explicitly defines a binary comparison operator of std::string vs. char*).
I did not explore the function where the second error comes from
(tools/clang/lib/Sema/SemaExpr.cpp:6798, same revision).
Reproduction: Compile the attached file with clang++ -g test2.cc (note the lack
of error or warning), and
lldb a.out
break set -f test2.cc -l 8
run
expr abc == "abc"
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140809/3fee9419/attachment.html>
More information about the lldb-dev
mailing list