[clang-tidy] clang-analyzer-core.CallAndMessage and clang-analyzer-alpha.deadcode.UnreachableCode

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(“,”)))
^
/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(“,”)))
^
/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(“,”)))
^
/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(“,”)))
^
/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(“,”)))

Code looks like this:

void parseAggregate(std::string& key, std::vectorstd::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> tokenizer;
for(const auto& token: tokenizer(aggregate.begin()+pos+1, aggregate.end(), boost::char_separator(“,”)))
values.push_back(token);
}

Is it bug in the analyzer, or boost::tokenizer is broken? (1.55)

Best
Piotr Padlewski

Hi Piotr,

Sure, I will do it tomorrow when I will have full source code.

https://llvm.org/bugs/show_bug.cgi?id=25777

Piotr