[cfe-dev] [clang-tidy] clang-analyzer-core.CallAndMessage and clang-analyzer-alpha.deadcode.UnreachableCode
Piotr Padlewski via cfe-dev
cfe-dev at lists.llvm.org
Fri Nov 27 08:18:16 PST 2015
Hi guys,
So I was running clang-tidy on some larger code base recently, and I got
warning like this:
warning: optimization flag '-fno-inline-functions-called-once' is not
supported [clang-diagnostic-ignored-optimization-argument]
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: warning:
Called C++ object pointer is uninitialized
[clang-analyzer-core.CallAndMessage]
for(const auto& token: tokenizer(aggregate.begin()+pos+1,
aggregate.end(), boost::char_separator<char>(",")))
^
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:13:8: note:
Assuming 'pos' is not equal to 'npos'
if(pos == std::string::npos)
^
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:13:5: note:
Taking false branch
if(pos == std::string::npos)
^
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:28: note:
'__range' initialized to a garbage value
for(const auto& token: tokenizer(aggregate.begin()+pos+1,
aggregate.end(), boost::char_separator<char>(",")))
^
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: note:
Called C++ object pointer is uninitialized
for(const auto& token: tokenizer(aggregate.begin()+pos+1,
aggregate.end(), boost::char_separator<char>(",")))
^
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: warning:
This statement is never executed
[clang-analyzer-alpha.deadcode.UnreachableCode]
for(const auto& token: tokenizer(aggregate.begin()+pos+1,
aggregate.end(), boost::char_separator<char>(",")))
^
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: note: This
statement is never executed
for(const auto& token: tokenizer(aggregate.begin()+pos+1,
aggregate.end(), boost::char_separator<char>(",")))
Code looks like this:
void parseAggregate(std::string& key, std::vector<std::string>& values,
const std::string& aggregate)
{
std::string::size_type pos = aggregate.find('=');
if(pos == std::string::npos)
throw FastException("Expected \"key=value,value...\" format.");
key = aggregate.substr(0, pos);
values.clear();
typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
for(const auto& token: tokenizer(aggregate.begin()+pos+1,
aggregate.end(), boost::char_separator<char>(",")))
values.push_back(token);
}
Is it bug in the analyzer, or boost::tokenizer is broken? (1.55)
Best
Piotr Padlewski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151127/0e7624de/attachment.html>
More information about the cfe-dev
mailing list